Autocompletetextview commonly used 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
Basic Usage:
1. Declare the component in an XML file
Reference:
< Autocompletetextview android:id = "@+id/ Activity_tab_search_autocomplete " android:layout_width = "fill_parent" android:layout_height =" fill_parent " android:layout_marginleft =" 5DP " android:dropdownhorizontaloffset = "0DP" android:completionthreshold = "1" android:background = "@null" />
2. Create a List_item.xml file in the layout directory to display the item
Reference:
<?xml version= "1.0" encoding= "Utf-8"?><linearlayout xmlns:android="Http://schemas.android.com/apk/res/android" Android:layout_width="Match_parent"android:layout_height="Fill_parent" Android:orientation="vertical" > <linearlayoutandroid:layout_width="Match_parent"android:layout_height ="30DP"android:orientation="vertical"android:gravity="Center_ Vertical " > "<TextViewandroid:id="@+id/list_search_choose_item_textview"android: Layout_width="Wrap_content"android:layout_height="Wrap_content"android: Layout_marginleft="20DP"android:text="XXX"android:textsize= "18sp" /> </linearlayout></linearlayout>
3. Code section
string[] str = new string[] { "medical Record number" , "patient Name" , "status" , "date" } Autocompletetextview actv= (Autocompletetextview) mviewsearch.findViewById (R.id .activity _tab_search_ AutoComplete) arrayadapter<string> arrayadapter = new arrayadapter<string> (this,r .list _item,r.id Span class= "Hljs-preprocessor" >.list _search_choose_item_textview, str) ; Actv.setadapter (arrayadapter) ;
————————————————————————————————————————————————————————
set no input and auto-complete
In two steps:
1. In the XML file, add the attribute on the parent container of the Autocompletetextview :
android:focusable="true"android:focusableInTouchMode="true"
The effect is to set the focus after the click, that is, does not automatically get focus.
In 2.java code, focus monitoring is set for Autocompletetextview
actv.setOnFocusChangeListener(new OnFocusChangeListener() { @Override publicvoidonFocusChangeboolean hasFocus) { // TODO Auto-generated method stub AutoCompleteTextView view=(AutoCompleteTextView)v; if (hasFocus) { view.showDropDown(); } } });
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Use of components (iii) use of Autocompletetextview