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