In this paper, the use of Autocompletetextview and Multiautocompletetextview in Android is illustrated, using the following methods:
First look at the use of Autocompletetextview:
Supports basic AutoComplete, applies to various search functions, and can set his default display data to suit your needs.
Two controls can be flexible to preset matching data, and can set the number of input values to start matching and so on.
The layout file is simple, as follows:
<linearlayout xmlns: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" >
<autocompletetextview
android:id= "@+id/tv"
android: Layout_width= "Fill_parent"
android:layout_height= "wrap_content"/>
</LinearLayout>
Here need to explain that layout_width should not be set to wrap_content, otherwise the drop-down prompts can only see the first hint, the following content is not visible .
The business code is as follows:
protected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_main);
Mtextview = (Autocompletetextview) Findviewbyid (r.id.tv);
arrayadapter<string> adapter = new Arrayadapter<string> (this, Android. R.LAYOUT.SIMPLE_DROPDOWN_ITEM_1LINE,AUTOSTR);
Mtextview.setadapter (adapter);
}
Use of Multiautocompletetextview:
The control can support selecting multiple values (in the case of multiple entries), separating them separately, and automatically matching each value when it is selected again.
Use this type of contact when texting and sending a message.
The set separator method needs to be performed when used.
the use of Multiautocompletetextview is similar to Autocompletetextview, except that you need to set the separator :
The specific use method is to add after the Setadapter () method:
Mtextview.settokenizer (New Multiautocompletetextview.commatokenizer ());