代码之家  ›  专栏  ›  技术社区  ›  Spredzy

如何在ListView上设置EditText?

  •  0
  • Spredzy  · 技术社区  · 15 年前

    我正在尝试按我的方式(逻辑,布局, 等等),所以我不想使用autocompleteTextView。 我的问题是如何在类的ListView上设置EditText 从Listacvity继承。

    我试过两种布局,都不管用。

    第一个:

       <EditText android:id="@+id/autocomplete_server" 
                 android:layout_width="fill_parent" 
                 android:layout_height="wrap_content" 
                 android:layout_marginLeft="5dp" 
                 android:completionThreshold="1" 
                 android:singleLine="true"/> 
    
        <ListView  android:id="@id/android:list" 
                   android:layout_width="fill_parent" 
                   android:layout_height="fill_parent" 
                   android:background="#000000" 
                   android:layout_weight="1" 
                   android:drawSelectorOnTop="false"/> 
    
         <TextView android:id="@id/android:empty" 
                   android:layout_width="fill_parent" 
                   android:layout_height="fill_parent" 
                   android:background="#FF0000" 
                   android:text="No data"/> 
    

    这个只显示编辑文本,但不显示列表 第二种:

       <LinearLayout  android:id="@id/android:list" 
                      android:orientation="horizontal" 
                      android:layout_width="fill_parent" 
                      android:layout_height="wrap_content" 
                      android:padding="5dp"> 
    
        <EditText  android:id="@+id/autocomplete_server" 
                   android:layout_width="fill_parent" 
                   android:layout_height="wrap_content" 
                   android:layout_marginLeft="5dp" 
                   android:completionThreshold="1" 
                   android:singleLine="true"/> 
    
        <ListView  android:layout_width="fill_parent" 
                   android:layout_height="fill_parent" 
                   android:background="#000000" 
                   android:layout_weight="1" 
                   android:drawSelectorOnTop="false"/> 
    
         </LinearLayout> 
    

    这个例子给了我一个: java.lang.runtimeexception:无法启动活动 componentInfo com.eip.core/com.eip.core.search: java.lang.ClassCastException:android.widget.linearLayout

    有人知道如何在 一个ListVIEW?

    2 回复  |  直到 14 年前
        1
  •  2
  •   YaW    15 年前

    这对我很有用:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
    
        <EditText  
            android:id="@+id/autocomplete_server" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:layout_marginLeft="5dp" 
            android:completionThreshold="1" 
            android:singleLine="true"/> 
    
        <ListView  
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:background="#000000" 
            android:layout_weight="1" 
            android:layout_below="@id/autocomplete_server"
            android:drawSelectorOnTop="false"/> 
    
    </RelativeLayout>
    

    您必须填充ListView,否则看不到它。

        2
  •  1
  •   Vishwanath    15 年前

    我可以看到第二个布局中的方向设置为水平…尝试将其设置为垂直…

    android:orientation="vertical"