Android Development Autocompletetextview Controls

Source: Internet
Author: User

Autocompletetextview is an editable text that automatically displays a string that matches the part of the user input string and matches the position, from which to select.


Introduce several methods:

1.setAdapter ()

The auto-complete text box sets the adapter to display the matching string.

2.setThreshold ()

Enter the number of characters after which to start the match.

3.setThreshold ()

The parameter is a string that displays a match when the user enters a character with a match, and displays the hint message.

4.setDropDownBackgroundResource () and setdropdownbackgrounddrawable ()

Sets the background of the cue box.



Small instance:

Mainactivity.java

public class Mainactivity extends Activity {Autocompletetextview autocompletetextview; string[] str = {"Peach", "Pear", "Banana", "Honeydew", "Orange", "Tangerine"}; @Overridepublic void OnCreate (Bundle savedi Nstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); AutoCompleteTextView = ( Autocompletetextview) Findviewbyid (R.id.myview); arrayadapter<string> arrayadapter = new Arrayadapter<string> (Mainactivity.this, Android. R.LAYOUT.SIMPLE_DROPDOWN_ITEM_1LINE,STR);//Enter and exit 3 characters and start matching autocompletetextview.setthreshold (3);// Hint Information autocompletetextview.setcompletionhint ("Select an item");//Background Autocompletetextview.setdropdownbackgroundresource ( R.drawable.blue);//autocompletetextview.setdropdownbackgrounddrawable (d) Autocompletetextview.setadapter ( Arrayadapter);}}

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= "${relativepackage}.${activityclass}" >    < Autocompletetextview        android:id= "@+id/myview"        android:layout_width= "fill_parent"        android:layout_ height= "Wrap_content"/></linearlayout>

:




Android Development Autocompletetextview Controls

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.