Android Auto-Complete tips

Source: Internet
Author: User

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

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.