Autocompletetextview is an editable text that automatically displays a string that matches the part of the user input string and matches the position, from which to select.
Introduce several methods:
1.setAdapter ()
The auto-complete text box sets the adapter to display the matching string.
2.setThreshold ()
Enter the number of characters after which to start the match.
3.setThreshold ()
The parameter is a string that displays a match when the user enters a character with a match, and displays the hint message.
4.setDropDownBackgroundResource () and setdropdownbackgrounddrawable ()
Sets the background of the cue box.
Small instance:
Mainactivity.java
public class Mainactivity extends Activity {Autocompletetextview autocompletetextview; string[] str = {"Peach", "Pear", "Banana", "Honeydew", "Orange", "Tangerine"}; @Overridepublic void OnCreate (Bundle savedi Nstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); AutoCompleteTextView = ( Autocompletetextview) Findviewbyid (R.id.myview); arrayadapter<string> arrayadapter = new Arrayadapter<string> (Mainactivity.this, Android. R.LAYOUT.SIMPLE_DROPDOWN_ITEM_1LINE,STR);//Enter and exit 3 characters and start matching autocompletetextview.setthreshold (3);// Hint Information autocompletetextview.setcompletionhint ("Select an item");//Background Autocompletetextview.setdropdownbackgroundresource ( R.drawable.blue);//autocompletetextview.setdropdownbackgrounddrawable (d) Autocompletetextview.setadapter ( Arrayadapter);}}
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= "${relativepackage}.${activityclass}" > < Autocompletetextview android:id= "@+id/myview" android:layout_width= "fill_parent" android:layout_ height= "Wrap_content"/></linearlayout>
:
Android Development Autocompletetextview Controls