0

Check the code at http://developer.android.com/resources/tutorials/views/hello-autocomplete.html or

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp"
    android:textColor="#000">
</TextView>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:padding="5dp">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Country" />
    <AutoCompleteTextView android:id="@+id/autocomplete_country"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"/>
</LinearLayout>

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
    textView.setAdapter(adapter);
}

and then we have a static final String[] COUNTRIES filled with all the countries.

My Question is why are we using list_item.xml. actually list_item.xml contails the 1st part of the code and the 2nd xml code is for main.xml and then the java code for activity

Housefly
  • 4,324
  • 11
  • 43
  • 70

1 Answers1

2

Results in an autocompletetextview is shown in list form. each item in the list requires a layout. R.layout.list_item is the layout for the each item in the list

Mark Pazon
  • 6,167
  • 2
  • 34
  • 50
  • u mean the autocompletetextview drop down box i get when i type few letters consists of items which actually are layouts(list_item) ?? – Housefly Apr 06 '12 at 10:03
  • yes. if you dont want to create your own layout, there are actually built in layouts that you can use. Most popular is android.R.layout.simple_list_item_1 – Mark Pazon Apr 06 '12 at 10:06