Android Learning Autocompletetextview and Multiautocompletetextview

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/qq_28468727/article/details/52258409

Autocompletetextview, Multiautocompletetextview automatically complete controls for input content

If we want to implement user input content has automatic prompt function, similar to Baidu search results, Autocompletetextview and Multiautocompletetextview can achieve similar function

Mainactivity.java:

 Public classMainactivityextendsappcompatactivity {PrivateAutocompletetextview Autotextview; PrivateMultiautocompletetextview Multiautocompletetextview; PrivateArraylist<string>list; PrivateArrayadapter<string>adapter; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);            Setcontentview (R.layout.activity_main); Autotextview=(Autocompletetextview) Findviewbyid (R.id.autotext); Multiautocompletetextview=(Multiautocompletetextview) Findviewbyid (R.id.multiauto); //Initializing a listList =NewArraylist<string>(); List.add ("123456"); List.add ("12345"); List.add ("1234"); List.add ("Google"); List.add ("Goole Map"); List.add ("Goole Chrome"); //Initialize adapter adapter using data from List//The second parameter indicates that the adapter is in a drop-down styleadapter =NewArrayadapter<string> ( This, Android.          R.layout.simple_dropdown_item_1line,list); //add an adapter for AutocompletetextviewAutotextview.setadapter (adapter); //Multiautocompletetextview Adding adaptersMultiautocompletetextview.setadapter (adapter); //complete the split of options, separated by commasMultiautocompletetextview.settokenizer (NewMultiautocompletetextview.commatokenizer ()); }  }  

Activity_main.xml:

<?XML version= "1.0" encoding= "Utf-8"?>  <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"Tools:context= "Com.example.administrator.edittextdemo.MainActivity">        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/textview1"Android:text= "Autocompletetextview"/>        <AutocompletetextviewAndroid:id= "@+id/autotext"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" />        <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/textview2"Android:text= "Multiautocompletetextview"/>        <MultiautocompletetextviewAndroid:id= "@+id/multiauto"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" />  </LinearLayout>  

Android Learning Autocompletetextview and Multiautocompletetextview

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.