Autocompletetextview: Each text box can only match once
Multiautocompletetextview: Ability to match multiple occurrences of a split point with a delimiter
1 XML example of//autocomplete2 <Autocompletetextview3 Android:completionthreshold= "3"//input number reaches 3 o'clock start display prompt4 Android:id= "@+id/autocompletetextview1"5 Android:layout_width= "Match_parent"6 Android:layout_height= "Wrap_content"7 Android:layout_alignparentleft= "true"8 Android:layout_alignparenttop= "true"9 Android:ems= "Ten"Ten Android:hint= "Please enter keywords" > One </Autocompletetextview>
1 //AutoComplete Java Sample2 3 Public classMainactivityextendsActivity {4 PrivateAutocompletetextview Actextview;5 PrivateString[] res = {"Beijing1", "Beijing2", "Beijing3",//Prompt Resource6"Shanghai1", "SHANGHAI2"};7 8 @Override9 protected voidonCreate (Bundle savedinstancestate) {Ten Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.fragment_main); A /** - * 1. Initialize the control - * 2, need an adapter,arrayadapter<string> the * 3, initialize the data source---match text box input content - * 4, bind adapter with Autocompletetextview - */ - +Actextview =(Autocompletetextview) Findviewbyid (r.id.autocompletetextview1); -arrayadapter<string> adapter =NewArrayadapter<> ( This, +Android. R.layout.simple_list_item_1, RES);//3 Parameters: Context, layout, resource AActextview.setadapter (adapter);//binding at } -}
1 //multiautocompletetextview XML Example2 3 <Multiautocompletetextview4 Android:id= "@+id/multiautocompletetextview1"5 Android:layout_width= "Match_parent"6 Android:layout_height= "Wrap_content"7 Android:layout_alignparentleft= "true"8 Android:layout_alignparenttop= "true"9 Android:ems= "Ten"Ten Android:hint= "Please enter keywords" />
1 //Java example of Multiautocompletetextview2 3 Public classMainactivityextendsActivity {4 PrivateMultiautocompletetextview Mactextview;5 PrivateString[] res = {"Beijing1", "Beijing2", "Beijing3",6"Shanghai1", "SHANGHAI2"};7 8 @Override9 protected voidonCreate (Bundle savedinstancestate) {Ten Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.fragment_main); A /** - * 1. Initialize the control - * 2, need an adapter,arrayadapter<string> the * 3, initialize the data source---match text box input content - * 4, bind adapter with Autocompletetextview - * 5, set the separator - */ + -Mactextview =(Multiautocompletetextview) Findviewbyid (r.id.multiautocompletetextview1); +arrayadapter<string> adapter =NewArrayadapter<> ( This, A Android. R.layout.simple_list_item_1, res); at Mactextview.setadapter (adapter); - //set a comma as a separator -Mactextview.settokenizer (NewMultiautocompletetextview.commatokenizer ()); - //in System customization, delimiters are comma-only, others need to be set to their own - } -}
2014-08-16