I. Introduction of Multiautocompletetextview
1. Function: can support the selection of multiple values (in the case of multiple input), separated by separators, and when each value is selected again automatically go to match, can be used to send text messages, e-mail to select the type of contact.
2. Properties: android:completionthreshold= "2"
3. Set the delimiter: Mtxt.settokenizer (New Multiautocompletetextview.commatokenizer ());
Second, Autocompletetextview Introduction:
1. Function: Just a single dynamic match
2. Attribute android:completionthreshold= "n"--enter n characters to start matching (same as Multiautocompletetextview)
Third, the implementation of the steps:
1.AutoCompleteTextView:
First step: Initialize the control
Step Two: An adapter is required to fit the contents of the current text box input.
with a simple adapter Arrayadapter
Step Three: Initialize the data Source = = = To match the content entered in the text box.
eg:private string[]={,,};
using generics
arrayadapter<string> adapter = new Arrayadapter<string> (,,);
Fourth step: match the adapter with the current Autocompletetextview.
Actextview.steadapter (adapter);
2.MultiAutoCompleteTextView
/**
* 1 Initialize Control
* 2 requires an adapter
* 3 Initializing data source
* 4 binds to the current multiAutocompletetextview
* 5 Set delimiter
* Mactestview.settokenizer (new Multiautocompletetextview.commatokenizer ());//comma delimited
*/
Iv. Implementing in Code
&NBSP; 1. add Autocompletetextview and Multiautocompletetextview to Activity_main.xml
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" > <autocompletetextview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:completionthreshold= "3" android:hint= "Please enter the keyword you want to search" android:id= "@+id/autocompletetextview" android:layout_below= "@+id/textview" android:layout_alignparentleft= "true" android:layout_ Alignparentstart= "true" /> <multiautocompletetextview android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:hint= "Please enter the keyword you want to search" android:id= "@+id/ Multiautocompletetextview " android:layout_below=" @+id/autocompletetextview " android: Completionthreshold= "2" /></span>
2. Specifically implemented in Maniactivity.class:
/span>
Package Com.example.administrator.paoma;import Android.support.v7.app.actionbaractivity;import Android.os.Bundle; Import Android.view.menu;import Android.view.menuitem;import Android.widget.arrayadapter;import Android.widget.autocompletetextview;import Android.widget.multiautocompletetextview;public class MainActivity Extends Actionbaractivity {string[] guan = new string[]{"Beijing1", "Beijing2", "Bejing", "Shanghai1", "Shangh Ai2 "," Shnghai3 "};//create an adapter for subsequent calls to private Autocompletetextview atCo; Private Multiautocompletetextview Mactextview; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); /* * */AtCo = (Autocompletetextview) Findviewbyid (R.id.autocompletetextview);//Initialize Autocompletetext View arrayadapter<string> adapter = new Arrayadapter<string> (this, Android. R.layout.simple_list_item_1,guan);//Initialization ofAdapter Atco.setadapter (adapter); Binds to the current Autocompletetextview Mactextview = (multiautocompletetextview) Findviewbyid (R.id.multiautoco Mpletetextview);//Initialize Multiautocompletetextview Mactextview.setadapter (adapter);// Binds to the current Multiautocompletetextview Mactextview.settokenizer (New Multiautocompletetextview.commatokenizer ());// Comma-delimited}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Self-paced notes Multiautotextview features, special attributes, usage (differences and approximations to Autotextview)