Wednesday 14 November 2012

Steps to design AutoCompleteTextView

Steps:
1.Create the xml file with AutoCompleteTextView
Ex:
<AutoCompleteTextView
        android:id="@+id/auto"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="2" />

2.Get the reference of AutoCompleteTextView to the Acivity.
Ex:
AutoCompleteTextView auto = (AutoCompleteTextView)findViewById(R.id.auto);

3.Create the String array with the suggestion values.
Ex:
String[] subjects = { "Android", "AndroidBooks", "AndroidGames","AndroidTheames", "AndroidMobiles", "AndroidTablets","AndroidDeveloper", "AndroidSoftware" };

4.Create the ArrayAdapter object for holding the suggestion Values.
Ex:
ArrayAdapter adapter = new ArrayAdapter
 (this,android.R.layout.simple_list_item_1, subjects);

5.Attach the ArrayAdapter object to AutoCompleteTextView.
Ex:
auto.setAdapter(adapter);



No comments:

Post a Comment