Android implements the search box to automatically complete the text box in the XML file code as follows:
1<?xml version="1.0"encoding="Utf-8"?>2<LinearLayout3Xmlns:android="http://schemas.android.com/apk/res/android"4android:orientation="Vertical"5Android:layout_width="fill_parent"6android:layout_height="fill_parent">7 8<Autocompletetextview9Android:id="@+id/myautocompletetextview"TenAndroid:layout_width="fill_parent" Oneandroid:layout_height="wrap_content"/> A -</LinearLayout>
The Java file code is as follows:
1 Package Com.example.sample_5_1;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 ImportAndroid.widget.ArrayAdapter;6 ImportAndroid.widget.AutoCompleteTextView;7 8PublicclassAutocompleteactivity extends Appcompatactivity {9private static final string[] MyStr =New string[]{Ten "Vae","Victory","Vision","Virtue","Vital" One }; A @Override - protected void OnCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); the Setcontentview (r.layout.activity_auto_complete); -arrayadapter<string> AA = new arrayadapter<string> (//Create an adapter -This,//Context - Android. R.layout.simple_dropdown_item_1line, +//use the simple layout that comes with Android -MYSTR); //Resource Array +Autocompletetextview Myautocompletetextview = A (Autocompletetextview) Findviewbyid (R.id.myautocompletetextview); at//get a reference to a control -Myautocompletetextview.setadapter (AA); //setting up the adapter -Myautocompletetextview.setthreshold (1); //define the number of characters that require user input - } -}as follows: (Enter a V to automatically prompt for all content starting with V)
Android implements auto-complete text box in search box