The use of Autocompletetextview and Multiautocompletetextview in Android _android

Source: Internet
Author: User

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 ());
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.