Use of Autocompletetextview controls for Android Studio development Basics

Source: Internet
Author: User

Enter The information we want to enter in the input box and there will be other hints associated with it, which is implemented in Android using Autocompletetextview. the Autocompletetextview control inherits from the TextView control and has its own properties:

Autocompletetextview Common Properties
Android:completionhint Set the prompt title that appears in the drop-down menu
Android:completionthreshold Set how many characters the user will enter at least to display a prompt
Android:dropdownhorizontaloffset The drop-down menu is offset horizontally between the text boxes. The default is left-aligned with the text box
Android:dropdownheight The height of the drop-down menu
Android:dropdownwidth The width of the drop-down menu
Android:singleline Single-line display
Android:dropdownverticaloffset Vertical offset

First, the effect:


Second, the code:

<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: paddingleft= "@dimen/activity_horizontal_margin" android:paddingright= "@dimen/activity_horizontal_margin" Android :p addingtop= "@dimen/activity_vertical_margin" android:paddingbottom= "@dimen/activity_vertical_margin" tools: Context= ". Mainactivity "android:orientation=" vertical "> <textview android:text=" Please enter search keywords: "android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:textsize= "30DP"/> <autocompletete Xtview android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:id= "@+id/KeyWo RDS "android:textsize=" 30DP "/> <button android:layout_width=" Wrap_content "android:layout_he ight= "Wrap_content" android:layout_gravity= "Center_hoRizontal "android:text=" search "android:textsize=" 35DP "/></linearlayout> 

Package Com.example.lhb.autocompletetextview;import Android.app.searchableinfo;import Android.support.v7.app.actionbaractivity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.widget.arrayadapter;import Android.widget.autocompletetextview;public Class Mainactivity extends Actionbaractivity {@Override protected void onCreate (Bundle savedinstancestate) {Super        . OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);    Search (); } private void Search () {string[]aut=new string[]{"Android", "Android Software", "Android Project", "Android Stu        Dio "};        Arrayadapter<string> adapter=new arrayadapter<string> (This,r.layout.abc_simple_dropdown_hint,aut);        Autocompletetextview textview= (Autocompletetextview) Findviewbyid (r.id.keywords);    Textview.setadapter (adapter); }}


Use of Autocompletetextview controls for Android Studio development Basics

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.