Autocompletetextview can realize when the user input information automatically prompt function, but Autocompletetextview can only prompt once, and Multiautocompletetextview can also realize the function of information hint, And it is separated by commas to implement multiple hints.
Activity_main.xml:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "Android:orienta tion= "vertical" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen/activity_ Vertical_margin "tools:context=" com.example.autocompletetextviewdemo.MainActivity "> <textview android: Layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "Autocompletetextview"/> <autocompletetextview android:id= "@+id/autotext" android:layout_width= "Fill_parent" android:layou t_height= "Wrap_content"/> <textview android:layout_width= "fill_parent" android:layout_height= "wrap _content "android:text=" Multiautocompletetextview "/> <multiautocompletetextview android:id= "@+id/mul" android:layout_width= "Fill_parent" Andro id:layout_height= "Wrap_content"/></linearlayout>
Mainactivity.java:
Import Android. R.anim;import android.app.activity;import android.os.bundle;import Android.view.menu;import android.view.MenuItem; Import Android.widget.adapter;import Android.widget.arrayadapter;import Android.widget.AutoCompleteTextView; Import Android.widget.multiautocompletetextview;public class Mainactivity extends Activity {private Autocompletetextview autocompletetextview;private Multiautocompletetextview multiautocompletetextview;@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); Autocompletetextview = (Autocompletetextview) Findviewbyid (R.id.autotext); String auto[] = new string[] {Computer Academy, School of Computer Science and technology, Google, GoogleMap};//The second parameter represents the drop-down style of the adapter arrayadapter<string > adapter = new arrayadapter<string> (Mainactivity.this, Android. R.layout.simple_dropdown_item_1line,auto); Autocompletetextview.setadapter (adapter); Multiautocompletetextview = ( Multiautocompletetextview) Findviewbyid (R.id.mul);Multiautocompletetextview.setadapter (adapter); Multiautocompletetextview.settokenizer (new Multiautocompletetextview.commatokenizer ());//complete the Split function for the option, split with a comma}}
Android------autocompletetextview