Transferred from: http://blog.csdn.net/qq_28468727/article/details/52258409
Autocompletetextview, Multiautocompletetextview automatically complete controls for input content
If we want to implement user input content has automatic prompt function, similar to Baidu search results, Autocompletetextview and Multiautocompletetextview can achieve similar function
Mainactivity.java:
Public classMainactivityextendsappcompatactivity {PrivateAutocompletetextview Autotextview; PrivateMultiautocompletetextview Multiautocompletetextview; PrivateArraylist<string>list; PrivateArrayadapter<string>adapter; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Autotextview=(Autocompletetextview) Findviewbyid (R.id.autotext); Multiautocompletetextview=(Multiautocompletetextview) Findviewbyid (R.id.multiauto); //Initializing a listList =NewArraylist<string>(); List.add ("123456"); List.add ("12345"); List.add ("1234"); List.add ("Google"); List.add ("Goole Map"); List.add ("Goole Chrome"); //Initialize adapter adapter using data from List//The second parameter indicates that the adapter is in a drop-down styleadapter =NewArrayadapter<string> ( This, Android. R.layout.simple_dropdown_item_1line,list); //add an adapter for AutocompletetextviewAutotextview.setadapter (adapter); //Multiautocompletetextview Adding adaptersMultiautocompletetextview.setadapter (adapter); //complete the split of options, separated by commasMultiautocompletetextview.settokenizer (NewMultiautocompletetextview.commatokenizer ()); } }
Activity_main.xml:
<?XML version= "1.0" encoding= "Utf-8"?> <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context= "Com.example.administrator.edittextdemo.MainActivity"> <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/textview1"Android:text= "Autocompletetextview"/> <AutocompletetextviewAndroid:id= "@+id/autotext"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" /> <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/textview2"Android:text= "Multiautocompletetextview"/> <MultiautocompletetextviewAndroid:id= "@+id/multiauto"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" /> </LinearLayout>
Android Learning Autocompletetextview and Multiautocompletetextview