Auto-completion hints The main thing is to use the Autocompletetextview control, which is then prompted from the collection of strings that are provided by the Arrayadapter associated with the control.
First
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/53/71/wKioL1RnicvDHL1GAABrTtytVXk343.jpg "title=" Untitled. png "alt=" wkiol1rnicvdhl1gaabrttytvxk343.jpg "/>
The Autocompletetextviewactivity.java code is as follows:
public class autocompletetextviewactivity extends activity { @ Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (R.layout.autocomplete); Settitle ("autocompletetextview_activity"); arrayadapter< String> adapter = new arrayadapter<string> ( this, android. r.layout.simple_dropdown_item_1line, countries);//The 3rd parameter is the array name that provides the data autocompletetextview autotextview = (AutocOmpletetextview) findviewbyid (r.id.auto_complete); Autotextview.setadapter (adapter);//Add the adapter adapter to auto: Object autotextview.setthreshold (1);//Set Enter a few letters to start association, default is 2 }static final String[] COUNTRIES = new String[] { //Set data source "China" , "Russia", "Germany", "Ukraine", "Belarus", "USA" &NBSP;, "China1" , "China12", "Germany1", "Russia2", "Belarus1", "USA1" &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;};
The XML file in layout is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Wrap_content " > <autocompletetextview android:id= "@+id/auto_complete" android:layout_width= "Fill_parent" a ndroid:layout_height= "Wrap_content"/></linearlayout>
Of course, in order to modify the data source and code at a later convenience, it is recommended to add the data to the layout of the Strings.xml file
<?xml version= "1.0" encoding= "Utf-8"?> <resources> <string-array name= "Countries_array" > <item>China</item> <item>China1</item> <item>China12</item> </string-array> </resources>
Then modify the original data source as follows
string[] countries = getresources (). Getstringarray (R.array.countries_array);
This article from "leisurely Stroll," the blog, reproduced please contact the author!
Android Auto-Complete tips