Android Auto-match text Autocompletetextview/multiautocompletetextview

Source: Internet
Author: User
Tags xml example

Autocompletetextview: Each text box can only match once

Multiautocompletetextview: Ability to match multiple occurrences of a split point with a delimiter

1 XML example of//autocomplete2      <Autocompletetextview3          Android:completionthreshold= "3"//input number reaches 3 o'clock start display prompt4 Android:id= "@+id/autocompletetextview1"5 Android:layout_width= "Match_parent"6 Android:layout_height= "Wrap_content"7 Android:layout_alignparentleft= "true"8 Android:layout_alignparenttop= "true"9 Android:ems= "Ten"Ten Android:hint= "Please enter keywords" > One      </Autocompletetextview>    
1         //AutoComplete Java Sample2 3  Public classMainactivityextendsActivity {4     PrivateAutocompletetextview Actextview;5     PrivateString[] res = {"Beijing1", "Beijing2", "Beijing3",//Prompt Resource6"Shanghai1", "SHANGHAI2"};7     8 @Override9     protected voidonCreate (Bundle savedinstancestate) {Ten         Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.fragment_main); A         /** - * 1. Initialize the control - * 2, need an adapter,arrayadapter<string> the * 3, initialize the data source---match text box input content - * 4, bind adapter with Autocompletetextview -          */ -          +Actextview =(Autocompletetextview) Findviewbyid (r.id.autocompletetextview1); -arrayadapter<string> adapter =NewArrayadapter<> ( This,  +Android. R.layout.simple_list_item_1, RES);//3 Parameters: Context, layout, resource AActextview.setadapter (adapter);//binding at     } -}

1 //multiautocompletetextview XML Example2 3     <Multiautocompletetextview4         Android:id= "@+id/multiautocompletetextview1"5 Android:layout_width= "Match_parent"6 Android:layout_height= "Wrap_content"7 Android:layout_alignparentleft= "true"8 Android:layout_alignparenttop= "true"9 Android:ems= "Ten"Ten Android:hint= "Please enter keywords" />

1        //Java example of Multiautocompletetextview2 3  Public classMainactivityextendsActivity {4     PrivateMultiautocompletetextview Mactextview;5     PrivateString[] res = {"Beijing1", "Beijing2", "Beijing3",6"Shanghai1", "SHANGHAI2"};7     8 @Override9     protected voidonCreate (Bundle savedinstancestate) {Ten         Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.fragment_main); A         /** - * 1. Initialize the control - * 2, need an adapter,arrayadapter<string> the * 3, initialize the data source---match text box input content - * 4, bind adapter with Autocompletetextview - * 5, set the separator -          */ +          -Mactextview =(Multiautocompletetextview) Findviewbyid (r.id.multiautocompletetextview1); +arrayadapter<string> adapter =NewArrayadapter<> ( This,  A Android. R.layout.simple_list_item_1, res); at Mactextview.setadapter (adapter); -         //set a comma as a separator -Mactextview.settokenizer (NewMultiautocompletetextview.commatokenizer ());  -                                                     //in System customization, delimiters are comma-only, others need to be set to their own -     } -}

2014-08-16

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.