2010-04-06 90 views
0

我想要做一個自動完成版本我的方式(邏輯,佈局, 等...),所以我不想使用AutoCompleteTextView。 我的問題是如何在繼承自ListAcvitivy的類 的ListView頂部設置EditText。如何在ListView上設置EditText?

我嘗試了兩種佈局,他們都沒有工作。

第一招:

<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"/> 

這一次只顯示我的EditText,但不顯示列表 第二個:

<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

有沒有人有任何想法回合如何實現一個EditText的頂部 listView?

回答

2

這個工作對我來說:

<?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或者你看不到它。

+0

非常感謝它的工作! – Spredzy 2010-04-07 08:31:13

1

我可以看到你的第二個佈局方向設置爲水平...嘗試將其設置爲垂直....

android:orientation="vertical"