Use of components (iii) use of Autocompletetextview

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.