Android Control--autocompletetextview and Multiautocompletetextview (implements automatic matching of input content)

Source: Internet
Author: User

------------------------------------Autocompletetextview----------------------

1. How to use

Layout file

<LinearLayoutxmlns: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"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity " >    <AutocompletetextviewAndroid:id= "@+id/autocompletetextview1"Android:completionthreshold= "3"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:ems= "Ten"Android:hint= "Please enter keywords" >        <Requestfocus/>    </Autocompletetextview>    </LinearLayout>

Mainactivity.java

 PackageCom.example.mooc;ImportAndroid. R.anim;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.AutoCompleteTextView;ImportAndroid.widget.Button;ImportAndroid.widget.ImageButton;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {PrivateButton Login_button; PrivateImageButton Img_button; PrivateAutocompletetextview AutoCompleteTextView1; PrivateString res[] = {"Beijing1", "Beijing2", "Beijing3"}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //introduce the layout file to the activitySetcontentview (R.layout.auto_complete); /*** 1. Initialize an object * 2. Requires an adapter * 3. Initializing the data source * 4. Setting up the adapter*/AutoCompleteTextView1=(Autocompletetextview) Findviewbyid (R.ID.AUTOCOMPLETETEXTVIEW1); Arrayadapter<String> adapter =NewArrayadapter<string> ( This, Android.        R.layout.simple_list_item_1, RES);        Autocompletetextview1.setadapter (adapter); }

Effect:

-----------------------------Multiautocompletetextview------------------------------

Layout file:

    < Multiautocompletetextview         Android:id = "@+id/multiautocompletetextview1"         android:completionthreshold= "3"        android:layout_width= "Match_parent"          android:layout_height= "Wrap_content"        android:ems= "10"          android:hint= "Please enter your recipient"/>

Java code:

Private String res[] = {"Beijing1", "Beijing2", "Beijing3" };         /**          * 1. Initialize an Object 2. Requires an adapter 3. Initialize the data source 4. Set adapter 5. Set the delimiter          *         /= ( Multiautocompletetextview) Findviewbyid (r.id.multiautocompletetextview1);        Mutiple.setadapter (adapter);         // Set delimiter        Mutiple.settokenizer (new  Multiautocompletetextview.commatokenizer ());

Effect:

Android Control--autocompletetextview and Multiautocompletetextview (implements automatic matching of 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.