First, the function
Can support the selection of multiple values (in the case of multiple input), separated by a delimiter, and when each value is selected to re-enter the value will automatically go to match, can be used to send text messages, e-mail to select the type of contact
Ii. Unique Attributes
Android:completionthreshold = "2"--Automatically matches when setting the number of characters entered
Third, set the delimiter
Mtxt.settokenizer (New Multiautocompletetextview.commatokenizer ());--set comma as delimiter
Four, Code demonstration
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" > <MultiautocompletetextviewAndroid:id= "@+id/multiautocompletetextview1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:completionthreshold= "2"Android:hint= "Please enter keywords to search" > </Multiautocompletetextview> </LinearLayout>
PackageCom.muke.textview_edittext;ImportAndroid.os.Bundle;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.AutoCompleteTextView;ImportAndroid.widget.MultiAutoCompleteTextView;Importandroid.app.Activity; Public classMainactivityextendsactivity{PrivateMultiautocompletetextview Mautotextview; //Step Three: Initialize the data source--match what you entered in the text box PrivateString[] res = {"Beijing1", "Beijing2", "Beijing3", "Shanghai1", "Shanghai2", "Shenzhen1", "Shenzhen2", "guangzhou1", " GUANGZHOU2 "}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //First step: Find the control you want to manipulateMautotextview =(Multiautocompletetextview) Findviewbyid (R.ID.MULTIAUTOCOMPLETETEXTVIEW1); //Step Two: Need an adapter//Android. R.layout.simple_list_item_1: Is the system comes with the layoutarrayadapter<string> adapter =NewArrayadapter<string> ( This, Android. R.layout.simple_list_item_1, RES); //Fourth Step: Bind the adapter with the current AutocompletetextviewMautotextview.setadapter (adapter); //Fifth Step: Set the delimiter (this is comma-delimited)Mautotextview.settokenizer (NewMultiautocompletetextview.commatokenizer ()); }}
Multiautocompletetextview of Android controls (automatically matches input content)