AutoComplete text Box Autocompletetextview, when the user enters a certain character, the auto-complete text box displays a drop-down menu for the user to select, set a adapter, The Autocompletetextview preset text is encapsulated in the adapter
Main.xml
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" fill_parent " android:layout_height=" Fill_parent " android:orientation= "vertical" > <autocompletetextview android:id= "@+id/auto" android: Layout_width= "Fill_parent" android:layout_height= "wrap_content" android:completionhint= "Please choose your favorite book" android:dropdownhorizontaloffset= "20DP" android:completionthreshold= "1" /></linearlayout >
Mainactivity
Package Com.example.autocompletetextview;import Android.os.bundle;import Android.app.activity;import Android.view.menu;import Android.widget.arrayadapter;import Android.widget.autocompletetextview;public Class Mainactivity extends Activity {//define string array as hint text string[] books = new string[]{"AAA", "ABBB", "ACCC", "addd",};@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main);//Create a arrayadapter, encapsulate the array arrayadapter<string> AA = new Arrayadapter<string> (this Android. R.layout.simple_dropdown_item_1line,books); Autocompletetextview ACTV = (autocompletetextview) Findviewbyid (R.id.auto);//Set Adapteractv.setadapter (AA);}}
Android footstep---Auto-complete text box