The input boxes used to search for information in Baidu or Google can all display the relevant search keywords in the drop-down menu when we enter a small amount of text, you can select the keyword you want to search for to quickly obtain the required information. This function uses the automatically completed editable text input box control. In Android UI development, there is also a control named autocompletetextview. With this control, we can implement UI functions similar to the search box.
The following ataaw. com lists how to use autocompletetextview in Android.
A. The corresponding position declaration in the layout file automatically completes the Editable Space
<Autocompletetextview
Android: Id = "@ + ID/edittext"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
B.ProgramLoad Android Layout
Setcontentview (R. layout. autocompletetextview );
C. Construct a data source. Generally, an array is used or the data source is obtained through the database.
Private string [] ary = new string [] {
"Ataaw. com ",
"Anytime, anywhere ",
"Impromptu Times ",
"Android ",
"Google ",
};
D. Create an adapter for the space through the data source
Arrayadapter <string> adapter = new arrayadapter <string> (
This,
Android. R. layout. simple_dropdown_item_1line, // the style that comes with Android is used here.
Ary );
E. Create an adapter for the control
Autocompletetextview textview = (autocompletetextview) findviewbyid (R. Id. edittext );
Textview. setadapter (adapter );
So far, an automatically completed autocompletetextview editable text box is complete.
From: http://www.ataaw.com/develop/242.html