views:

62

answers:

2

Hi everyone,

I am trying to do an autocomplete version my way (logic, layout, etc...) , so I don't want to use the AutoCompleteTextView. My question is how to set an EditText on top of a ListView in a class inheriting from a ListAcvitivy.

I tried two kinds of layout, none of them worked.

First one :

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

This one only shows me the EditText but does not display the list Second one :

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

This sample gives me a : java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eip.core/com.eip.core.Search}: java.lang.ClassCastException: android.widget.LinearLayout

Does anyone have any idea bout how to implement an EditText on top of a listView ?

+1  A: 

I can see the orientation in your second layout is set to horizontal... Try setting it to Vertical....

android:orientation="vertical" 
Vishwanath
A: 

This works for me:

<?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>

You have to fill the ListView or you can't see it.

YaW
Thanks a lot it dit work !
Spredzy