Use Autocompletetextview in Android to enable auto-prompt function
In the Java document pre-set the need to prompt the string, the default is to enter two characters when the reminder, but can be used in the Java fileSetthreshold ()Method implementation change reminder is the number of characters entered, but the text of the reminder needs to be pre-matchedattached code:XML file:<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 = ".
Mainactivity " >
<TextView Android:layout_width=
"Fill_parent" Android:layout_height=
"Wrap_content" Android:text=
"Hello" />
<Autocompletetextview Android:id=
"@+id/autocomplete" Android:layout_width=
"Fill_parent" Android:layout_height=
"Wrap_content" > </Autocompletetextview > </LinearLayout> java files:
Package Com.just;
Import Android.os.Bundle;
Import android.app.Activity;
Import Android.widget.ArrayAdapter;
Import Android.widget.AutoCompleteTextView;
Public
class mainactivity
extends Activity {
Private
Static
Final string[]
Autostr =
New string[] { "a" , "ABC" , "ABCD" , "ABCDE", "ABCdef" }; @Override
protected
void onCreate (Bundle savedinstancestate) {
Super. OnCreate (savedinstancestate);Setcontentview (r.layout.
Activity_main);arrayadapter<?> adapter =
New arrayadapter<object> (
This,Android. R.layout.
Simple_dropdown_item_1line,
Autostr );Autocompletetextview Myautoview = (autocompletetextview) Findviewbyid (r.id.
AutoComplete );Myautoview.setthreshold (3);Myautoview.setadapter (adapter); } }PS: When using a new window, you must use adapter to achieve
Use Autocompletetextview in Android to enable auto-prompt function