The AutoCompleteTextView function is similar to the prompt that is close to the input information when Baidu or Google inputs information in the search bar. The result is an editable text view. A prompt is displayed after you enter the information. The prompt list is displayed in a drop-down menu, from which you can select one to complete the input. The prompt list is the data obtained from a data adapter.
Follow these steps:
Step 1: define controls in the layout File
- <AutoCompleteTextView
-
- android:id="@+id/actv"
-
- android:layout_width="fill_parent"
-
- android:layout_height="wrap_content"
-
- />
Step 2: reference in Activity
- AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv);
Step 3: Create an adapter to save data
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
-
- ndroid.R.layout.simple_dropdown_item_1line,new String[] {"English", "Hebrew", "Hindi", "German" });
Step 4: Associate the adapter with AutoCompleteTextView
- actv.setAdapter(adapter);