Android Basics Autocompletetextview and Multiautocompletetextview

Source: Internet
Author: User

Activity_main.xml
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"     xmlns: tools= "Http://schemas.android.com/tools"     android:layout_width= "Match_parent"      android:layout_height= "match_parent"     android:orientation= "vertical"     tools:context= "Com.vincentlin.completetextview.MainActivity"  >     <autocompletetextview        android:id= "@+id/ AutoCompleteTextView1 "        android:layout_width=" Match_parent "         android:layout_height= "Wrap_content"          android:completionthreshold= "2"         android : hint= "@string/autocompletetextview"  >        <requestfocus  />    </autocompletetextview>    <multiautocompletetextview         android:id= "@+id/multiautocompletetextview1"          Android:layout_width= "match_parent"         android:layout_height= "wrap _content "        android:hint=" @string/multiautocompletetextview "  /></LinearLayout>
Strings.xml
<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >completetextview</ string> <string name= "Hello_world" >hello world!</string> <string name= "Action_settings" >Settin gs</string> <string name= "Autocompletetextview" > Please enter the keywords you want to search </string> <string name= " Multiautocompletetextview "> Please enter your pickup </string></resources>
Mainactivity.java
Package com.vincentlin.completetextview;import android. R.anim;import android.app.activity;import android.os.bundle;import android.view.menu;import  android.view.MenuItem;import android.widget.ArrayAdapter;import  Android.widget.autocompletetextview;import android.widget.multiautocompletetextview;public class  MainActivity extends Activity { private AutoCompleteTextView acTextView;  private MultiAutoCompleteTextView muTextView; private String[] res =  {"Guangzhou1", "GUANGZHOU2", "Guangzhou3", "nanjing1", "Shanghai1"};   @Override  protected void  oncreate (bundle savedinstancestate)  {  super.oncreate (savedInstanceState);   setcontentview (r.layout.activity_main);    /*   *  First step: Initialize the control    *  Step Two: Need an adapter    *  step three: Initialize the data source--the content that matches the data source into the text box    *  Fourth: Bind the adapter with the current Autocompletetextview    */  acTextView =  ( Autocompletetextview)  findviewbyid (r.id.autocompletetextview1);  arrayadapter<string>  adapter = new ArrayAdapter<String> (this, android. R.layout.simple_list_item_1, res);   actextview.setadapter (adapter);       /*   *  can support the selection of multiple values, separated by separators, automatic matching, can be used to send messages or to send messages when you select a contact type    *  First step: Initialize the control    *  Step two: Require an adapter    *  step three: Initialize the data source--the content that matches the data source into the text box     *  Fourth Step: Bind adapter with current Autocompletetextview    *  Fifth step: Set delimiter    */   muTextView =  (Multiautocompletetextview)  findviewbyid (R.ID.MULTIAUTOCOMPLETETEXTVIEW1);   mutextview.setadapter (adapter);   //sets the end symbol with the comma delimiter   mutextview.settokenizer (new  multiautocompletetextview.commatokenizer ());  }}
//

650) this.width=650; "title=" Image 7.png "src=" http://s3.51cto.com/wyfs02/M00/58/9F/ Wkiol1s2fngzer0uaac6iluesmg538.jpg "alt=" Wkiol1s2fngzer0uaac6iluesmg538.jpg "/>

Android Basics Autocompletetextview and Multiautocompletetextview

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.