Simple use of Android Autocompletetextview

Source: Internet
Author: User

In Android development, it is often necessary to use the input character in an input box, and a list of current associations appears below. The control used here is Autocompletetextview

In the layout file

<autocompletetextview         android:id= "@+id/autotxtv"        android:layout_width= "Wrap_content"        android: layout_height= "Wrap_content"        android:dropdownwidth= "fill_parent"        android:ems= "ten"        Android: completionthreshold= "1"        android:dropdownanchor= "@+id/btn"        android:dropdownselector= "@drawable/btn_ Selector "/>

Simulate some data and put it in the array first

Private string[] Mstrings = {"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "abondance", "Ackawi", "Acorn", "Ade Lost "," Affidelice au Chablis "," Afuega ' L Pitu "," Airag "," Airedale "," Aisy cendre "," Allgauer Emmentaler "," Abbaye de Bello C "," Abbaye du Mont des Cats "," Abertam "," abondance "," Ackawi "," Acorn "," Adelost "," Affidelice au Chablis "," Afuega ' L Pitu "," Airag "," Airedale "," Aisy cendre "," Allgauer Emmentaler "};

Then you only need to use Arrayadapter to invoke the data, or you can use baseadapter based on your own actual business needs.

Arrayadapter<string> adapter=new arrayadapter<string> (Atutotxtvactivity.this, Android. R.layout.simple_list_item_1, mstrings); Auto.setadapter (adapter);

You can then add a listener event that requires some action when the input string changes

Auto.addtextchangedlistener (New Textwatcher () {@Overridepublic void ontextchanged (charsequence s, int start, int before , int count) {System.out.println ("==s-------" +s+ "==start==" +start+ "===before==" +before+ "==count==" +count);} @Overridepublic void Beforetextchanged (charsequence s, int start, int count,int after) {} @Overridepublic void Aftertextch Anged (Editable s) {toast.maketext (Atutotxtvactivity.this, s.tostring (), Toast.length_short). Show ();});

Three ways of meaning at a glance, this simple function is realized

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Simple use of Android Autocompletetextview

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.