The Autocompletetextview is somewhat similar to the EditText and spinner blends. When the user enters, if the auto-complete control is used in the application's text input box, the pre-input text is treated as a prefix filter, and the candidate text is displayed as a drop-down list after the user's current input is prefixed with the text. Similar to spanner, candidate text appears below the input area. The user can enter all text manually (for example, when there are no candidates in the list), or select the appropriate value from the drop-down list. Autocompletetextview is a subclass of EditText, so you can set its object to a property value such as appearance/font/color. In addition, Autocompletetextview has a property value named Android:completionthreshold that describes the number of characters that the user entered at least when the prefix filter was started. You can add an adapter (adapter) that contains a list of candidate values to Autocompletetextview by Setadapter (). However, because the user can enter some data that is not in the list of candidate values, Autocompletetextview does not support selection listener.
Common Properties:
Descriptive text below the Android:completionhint drop-down list
Android:completionthreshold the minimum number of characters to pop down the list
Android:dropdownanchor the anchor point or mount point of the drop-down list
Android:dropdownheight drop-down list height
Android:dropdownwidth drop-down list width
Android:dropdownhorizontaloffset drop-down list distance from left
Android:dropdownselector drop-down list the background of the row being selected
Instance:
1.:
2.XML Code:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Fill_parent"4 Android:layout_height= "Fill_parent"5 android:orientation= "vertical" >6 7 <Autocompletetextview8 Android:id= "@+id/auto"9 Android:layout_width= "Fill_parent"Ten Android:layout_height= "Wrap_content" One Android:completionhint= "Please select account:" A Android:completionthreshold= "1" - Android:dropdownhorizontaloffset= "0DP" /> - the </LinearLayout>
3.java Code:
1 PackageCom.example.autocompletetextview;2 3 ImportAndroid.os.Bundle;4 Importandroid.app.Activity;5 ImportAndroid.widget.ArrayAdapter;6 ImportAndroid.widget.AutoCompleteTextView;7 8 9 Public classMainactivityextendsActivity {Ten //defines a string array, as the text of the hint One string[] str = new string[] {"abc", "ABCD", "ABCDE", "abcdef"};
A -
- @Override the Public voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -arrayadapter<string> AA =NewArrayadapter<string> ( This, + Android. R.layout.simple_dropdown_item_1line, str); -Autocompletetextview ACTV =(Autocompletetextview) Findviewbyid (R.id.auto); + actv.setadapter (AA); A } at -}
The Autocompletetextview of Android learning