Basics of Android Basics tutorial--2.4.11 autocompletetextview (AutoComplete text box) basic use
tags (space delimited): Android Basics Getting Started Tutorial
Introduction to this section:
This section continues to learn the controls for the adapter class, this time with the Autocompletetextview (auto-complete text box),
I believe the careful you found, and adapter to the side of the control, you can define the item's style, right!
or the layout of each item ~ How to play on how to play ~ Well, words do not say, start the content of this section ~
Yes, put the official api:autocompletetextview.
1. Related properties:
- android:completionhint: Set the tip title in the drop-down menu
- Android:completionhintview: Show drop-down menu in the definition prompt view
- android:completionthreshold: Specifies how many characters the user will enter at least to display a prompt
- Android:dropdownanchor: Sets the anchor component of the drop-down menu, if no property is specified,
The TextView will be used as the Anchor point component
- android:dropdownheight: Setting the height of the drop-down menu
- android:dropdownwidth: Setting the width of the drop-down menu
- Android:dropdownhorizontaloffset: Specifies the horizontal spacing between the drop-down menu and the text
- android:dropdownverticaloffset: Specify vertical spacing between drop-down menus and text
- android:dropdownselector: Set drop-down menu click Effect
- android:popupbackground: Setting the background of the drop-down menu
In fact, there's a multiautocompletetextview(auto-complete text box with multiple hints)
And this Autocompletetextview function is similar, attributes are the same, specific differences in where,
We're going to experience this in the code below-and the other two are all word matches, like, Piggy Pig:
You input small and will prompt the pig pig, but the input pig----but will not prompt pig pig!
2. code example:
Run :
Implementation Code :
Here is not the custom layout, directly with Arrayadapter to achieve it!
Layout file:activity_main.xml:
<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android" Xmlns:tools="Http://schemas.android.com/tools"android:layout_width="Match_parent" android:layout_height="Match_parent"android:orientation="Vertical" Tools:context=". Mainactivity "> <autocompletetextview Android:id = "@+id/atv_content" android: Layout_width = "match_parent" android:layout_ Height = "48DP" android:completionhint = "Please enter search content" android:completionthreshold =< Span class= "Hljs-value" > "1" android:dropdownhorizontaloffset = "5DP" /> <multiautocompletetextviewandroid:id="@+id/matv_content"android:layout_ Width="Match_parent"android:layout_height="48DP"android: Completionthreshold="1"android:dropdownhorizontaloffset="5DP"android: Text="" /> </linearlayout>
Mainactivity.java:
Public class mainactivity extends appcompatactivity { PrivateAutocompletetextview atv_content;PrivateMultiautocompletetextview matv_content;Private Static Finalstring[] data =Newstring[]{"Piggy Pig","Puppy dog.","Small Chicken"," kitty Cat","Little Mimi."};@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<string> adapter =NewArrayadapter<string> (mainactivity. ThisAndroid. R.layout.simple_dropdown_item_1line, data); Atv_content.setadapter (adapter); Arrayadapter<string> Adapter2 =NewArrayadapter<string> (Getapplicationcontext (), Android. R.layout.simple_dropdown_item_1line, data); Matv_content.setadapter (adapter); Matv_content.settokenizer (NewMultiautocompletetextview.commatokenizer ()); }}
part of the Code Analysis :
- Android:completionthreshold= "1": here we set the input a word to display the prompt
- android:completionhint= "Please enter search Content": This is the text displayed at the bottom of the box, if you feel ugly
You can set a view! Android:completionhintview
- Android:dropdownhorizontaloffset= "5DP": Set the horizontal margin to 5DP
- Matv_content.settokenizer (New Multiautocompletetextview.commatokenizer ());
Settokenizer is to set the delimiter for it
3. Sample code Download:
Autocompletetextviewdemo.zip
This section summarizes:
This section introduces you to the Autocompletetextview (auto-complete text box), very simple ~
We can according to the actual development needs of self-expansion ~ Good, say so much, thank you ~
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Basics of Android Basics tutorial--2.4.11 autocompletetextview (AutoComplete text box) basic use