Multiautocompletetextview of Android controls (automatically matches input content)

Source: Internet
Author: User

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)

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.