Enter The information we want to enter in the input box and there will be other hints associated with it, which is implemented in Android using Autocompletetextview. the Autocompletetextview control inherits from the TextView control and has its own properties:
Autocompletetextview Common Properties |
Android:completionhint |
Set the prompt title that appears in the drop-down menu |
Android:completionthreshold |
Set how many characters the user will enter at least to display a prompt |
Android:dropdownhorizontaloffset |
The drop-down menu is offset horizontally between the text boxes. The default is left-aligned with the text box |
Android:dropdownheight |
The height of the drop-down menu |
Android:dropdownwidth |
The width of the drop-down menu |
Android:singleline |
Single-line display |
Android:dropdownverticaloffset |
Vertical offset |
First, the effect:
Second, the code:
<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: paddingleft= "@dimen/activity_horizontal_margin" android:paddingright= "@dimen/activity_horizontal_margin" Android :p addingtop= "@dimen/activity_vertical_margin" android:paddingbottom= "@dimen/activity_vertical_margin" tools: Context= ". Mainactivity "android:orientation=" vertical "> <textview android:text=" Please enter search keywords: "android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:textsize= "30DP"/> <autocompletete Xtview android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:id= "@+id/KeyWo RDS "android:textsize=" 30DP "/> <button android:layout_width=" Wrap_content "android:layout_he ight= "Wrap_content" android:layout_gravity= "Center_hoRizontal "android:text=" search "android:textsize=" 35DP "/></linearlayout>
Package Com.example.lhb.autocompletetextview;import Android.app.searchableinfo;import Android.support.v7.app.actionbaractivity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.widget.arrayadapter;import Android.widget.autocompletetextview;public Class Mainactivity extends Actionbaractivity {@Override protected void onCreate (Bundle savedinstancestate) {Super . OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Search (); } private void Search () {string[]aut=new string[]{"Android", "Android Software", "Android Project", "Android Stu Dio "}; Arrayadapter<string> adapter=new arrayadapter<string> (This,r.layout.abc_simple_dropdown_hint,aut); Autocompletetextview textview= (Autocompletetextview) Findviewbyid (r.id.keywords); Textview.setadapter (adapter); }}
Use of Autocompletetextview controls for Android Studio development Basics