Aoutcompletetextview
Function:1> dynamically match the input content, such as Baidu search engine when you enter text can be displayed according to the content of popular information matching
2> Unique properties: android:completionthreshold= "2" <!--set how many characters to automatically match
Layout layouts with automatic matching
<relativelayout 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"
Tools:context= ". Mainactivity ">
<autocompletetextview
Android:id= "@+id/autocompletetextview"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:hint= "Please enter a keyword to query"
Android:completionthreshold= "2" />
Automatic matching of class files
Package Cn.androidstudy.demo;
Import Android.os.Bundle;
Import android.app.Activity;
Import Android.view.Menu;
Import Android.widget.ArrayAdapter;
Import Android.widget.AutoCompleteTextView;
public class Mainactivity extends Activity {
Private Autocompletetextview Actextview;
Private string[] res = {"Shanghai", "Beijing", "tianjing", "Sichuan", "Yibin", "Sichuanjianzhuzhiyijishuxueyuan"};
@Override protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
/** * 1. Initialization control: actextview= (Autocompletetextview) * FINDVIEWBYLD (R.id.autocompletetextview)
* 2. Requires an adapter: Arrayadapter * <String> adapeter = new Arrayadapter<string> (this, * Android. R.layout.simple_expandable_list_item_1, RES);
* 3. Initialize the data source---this data source automatically matches the contents of the text box private string[] res = {"Shanghai", "Beijing", * "tianjing", "Sichuan", "Yibin", "Sichuanjian Zhuzhiyijishuxueyuan "};
* 4. Bind Adapeter and Aoutcompletetextview: Actextview.setadapter (Adapeter); * */
Actextview = (Autocompletetextview) Findviewbyid (R.id.autocompletetextview);
arrayadapter<string> adapeter = new Arrayadapter<string> (this, Android. R.layout.simple_expandable_list_item_1, RES);
Actextview.setadapter (Adapeter); }
@Override public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.main, menu); return true;
} }
Use of Android Aoutcompletetextview controls