Android basic getting started -- 2.4.11 AutoCompleteTextView (automatically complete text box) basic usage

Source: Internet
Author: User

Android basic getting started -- 2.4.11 AutoCompleteTextView (automatically complete text box) basic usage
1. related attributes:

Android: completionHint: Set the title of the prompt in the drop-down menu. Android: completionHintView: Display the drop-down menu in the definition prompt View Android: completionThreshold: Specifies how many characters a user can enter to display the prompt. Android: dropDownAnchor: Set the positioning "anchor" component in the drop-down menu. If the attribute is not specified,
The TextView will be used as the positioning "anchor" component Android: dropDownHeight: Set the height of the drop-down menu Android: dropDownWidth: Set the width of the drop-down menu Android: dropDownHorizontalOffset: Horizontal spacing between the drop-down menu and text Android: dropDownVerticalOffset: Specifies the Vertical spacing between the drop-down menu and text Android: dropDownSelector: Set the drop-down menu click Effect Android: popupBackground: Set the background of the drop-down menu

In addition, there isMultiAutoCompleteTextView(Automatic completion text box for multiple prompts)
Similar to the AutoCompleteTextView function, the attributes are the same. The specific differences are as follows,
Let's try the following code ~ The other two are all full-word matching, for example, pig:
If you enter "small->", a prompt will be displayed, but "input" is not displayed!

2. Sample Code:

Run:

Implementation Code:

Here we will not customize the layout. We can use ArrayAdapter to implement it directly!

Layout file:Activity_main.xml:


          
   
  

MainActivity. java:

Public class MainActivity extends AppCompatActivity {private AutoCompleteTextView atv_content; private MultiAutoCompleteTextView matv_content; private static final String [] data = new String [] {pig, dog, chicken, Cat, mi }; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); atv_content = (AutoCompleteTextView) findViewById (R. id. atv_content); matv_content = (MultiAutoCompleteTextView) findViewById (R. id. matv_content); ArrayAdapter
  
   
Adapter = new ArrayAdapter
   
    
(MainActivity. this, android. R. layout. simple_dropdown_item_1line, data); atv_content.setAdapter (adapter); ArrayAdapter
    
     
Adapter2 = new ArrayAdapter
     
      
(GetApplicationContext (), android. R. layout. simple_dropdown_item_1line, data); matv_content.setAdapter (adapter); Combine (new MultiAutoCompleteTextView. CommaTokenizer ());}}
     
    
   
  

Partial code analysis:

Android: completionThreshold = "1": here we set a word to display the prompt android: completionHint = "Enter the search content": This is the text displayed at the bottom of the box, if you feel ugly
You can set a View in android: completionHintView! Android: dropDownHorizontalOffset = "5dp": the horizontal margin is set to 5dp matv_content.setTokenizer (new MultiAutoCompleteTextView. CommaTokenizer ());
SetTokenizer sets a delimiter for it
  Summary:

This section introduces AutoCompleteTextView, which is very simple ~
You can expand it based on your actual development needs ~ Okay. That's all. Thank you ~

 

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.