Android advanced component ----- automatically edit text box, Android ----- text box

Source: Internet
Author: User

Android advanced component ----- automatically edit text box, Android ----- text box

The AutoCompleteTextView is inherited from EditText and can be input and edited by users. However, it has its own feature: after a certain number of characters are entered, a drop-down list prompt is displayed for users to choose from, the text box is automatically filled after the user selects it. This function is as prompted by the browser:

Because the automatic editing text box inherits from EditText, it supports all attributes of EditText, but it has its own unique attributes in the input prompt:

Android: completionHint: Specify the title for the pop-up drop-down menu

Android: completionThreshold: specifies the number of characters entered. A prompt is displayed.

Android: dropDownHeight: Specify the height of the drop-down menu

Android: dropDownHorizontalOffset specifies the horizontal offset between the drop-down menu and the text box.

Android: dropDownVerticalOffset specifies the vertical offset between the drop-down list and the text box.

Android: dropDownWidth: Specify the width of the drop-down menu

Android: popupBackground: Set the background for the drop-down menu

The input information is added in the input prompt box. Therefore, we need to configure the input prompt box through the adapter. Next we will create an AutoCompleteTextView with an input prompt box.

Instance operation:

1. Drag an Automatic completion edit box in the visual interface, and set a 2-character pop-up prompt and an edit box to the center of the layout.

<AutoCompleteTextView android: id = "@ + id/autoCompleteTextView1" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_gravity = "center" android: completionThreshold = "2" android: hint = "enter" android: EMS = "10"> <requestFocus/> </AutoCompleteTextView>

2. Create an adapter. The adapter can be created through a java array or resource file. Here we use the resource file to create the adapter

Resource file:

<?xml version="1.0" encoding="UTF-8"?><resources >    <string-array name="data">        <item >nanjing-xuanwu</item>        <item >nanjing-jiangning</item>        <item >nanjing-qixia</item>        <item >nanjing-jianye</item>    </string-array></resources>

 

Java code:

AutoCompleteTextView atc = (AutoCompleteTextView) findViewById (R. id. autoCompleteTextView1); // obtain the ArrayAdapter <CharSequence> aa = ArrayAdapter. createFromResource (this, R. array. data, R. layout. support_simple_spinner_dropdown_item); // create

3. Bind the adapter

      atc.setAdapter(aa);

Running result

Conclusion: AutoCompletionEditText is used to improve its prompt function. Tips are added using the adapter. For adapter creation, there are two types: resource file creation and java string creation.

 

Insufficient level. Leave a message if you are not clear. I will continue to correct it!

 

Related Article

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.