Android 0 Basic Getting Started section 47th: AutoComplete text Box Autocompletetextview

Source: Internet
Author: User

How about the use of spinner in the previous period of study? This issue together to learn the use of Autocompletetextview.

I. Understanding Autocompletetextview

Autocompletetextview is an auto-complete text box, derived from the edittext, it is actually a text edit box, but it is more than the normal edit box a function: When the user enters a certain character, the AutoComplete text box will display a drop-down menu for the user to choose from, When the user selects a menu item, Autocompletetextview automatically fills in the text box by user selection.

Autocompletetextview supports commonly used XML attributes and related methods, as shown in the following table, in addition to the XML properties and methods available with EditText.

Using Autocompletetextview is simple, as long as you set a adapter for it, the adapter encapsulates the hint text for the Autocompletetextview preset.

Autocompletetextview also derives a subclass: Multiautocompletetextview, which functions like Autocompletetextview basically, Just Multiautocompletetextview allows multiple prompt entries to be entered, and multiple prompt entries are delimited by delimiters. Multiautocompletetextview provides the Settokenizer () method to set the delimiter.

Ii. Examples of Autocompletetextview

Next, learn how to use Autocompletetextview and Multiautocompletetextview using a simple example program.

Continue to use the Listviewsample module of the Widgetsample project to create a autocomplete_textview_layout.xml file in the app/main/res/layout/directory populated with the following code snippet:

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <!--defines an AutoComplete text box, specifying that a character is entered to prompt -    <AutocompletetextviewAndroid:id= "@+id/auto_actv"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Enter contact name"Android:completionhint= "Select Contacts"Android:dropdownhorizontaloffset= "10DP"Android:completionthreshold= "1"/>    <!--defining a Multiautocompletetextview component -    <MultiautocompletetextviewAndroid:id= "@+id/mauto_mactv"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Enter contact name, can be separated by multiple separators"Android:completionthreshold= "1"/></LinearLayout>

The Autocompletetextview and Multiautocompletetextview are defined in the interface layout file above, and then the same adapter is bound for them in the program, which means that the two AutoComplete text boxes have the same prompt entries, It's just that they behave slightly differently.

Create a new Autocompletetextviewactivity.java file and load the new layout file above, with the following code:

 Packagecom.jinyu.cqkxzsxy.android.listviewsample;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.AutoCompleteTextView;ImportAndroid.widget.MultiAutoCompleteTextView; Public classAutocompletetextviewactivityextendsappcompatactivity {PrivateAutocompletetextview Mautotv =NULL; PrivateMultiautocompletetextview Mmultiautotv =NULL; //defines a string array, as the text of the hint    Privatestring[] Mcontacts =Newstring[]{"Test", "abc", "AAA", "AABBCC", "BAC", "OK", "say", "Aabbsd"    }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.autocomplete_textview_layout); Mautotv=(Autocompletetextview) Findviewbyid (R.ID.AUTO_ACTV); Mmultiautotv=(Multiautocompletetextview) Findviewbyid (R.ID.MAUTO_MACTV); //creates a arrayadapter, encapsulates an arrayarrayadapter<string> AA =NewArrayadapter<string> ( This, Android.        R.layout.simple_dropdown_item_1line, mcontacts); //Set Adaptermautotv.setadapter (AA);        Mmultiautotv.setadapter (AA); //set the delimiter for MultiautocompletetextviewMmultiautotv.settokenizer (NewMultiautocompletetextview.commatokenizer ()); }}

The above program code is responsible for setting the same Adapter for Autocompletetextview, Multiautocompletetextview, and a delimiter for Multiautocompletetextview.

Modify the program start activity, run the program, you can see the interface effect shown.

Enter the contents in two input boxes, respectively, and you can see the effect as shown.

At this point, the simple use of Autocompletetextview and Multiautocompletetextview learning is complete, more properties and methods are recommended to practice and master.

Come here today, if you have any questions welcome message to discuss together, also welcome to join the Android 0 Basic introductory Technical discussion group, grow together!

This article copyright for the public Share talent show (Shareexpert)--Xin 鱻 all, if necessary reprint please contact the author authorized, hereby declare!

Past period Summary share:

Android 0 Basics Introduction 1th: Android's past life

Android 0 Basics Section 2nd: Android system Architecture and application components those things

Android 0 Basics Section 3rd: Bring you up to talk about Android development environment

Android 0 Basics 4th: Installing and configuring the JDK correctly Ko fu the first trick

Android 0 Basics 5th: Use ADT bundles to easily meet the goddess

Android 0 Basics 6th: Configuration Optimization SDK Manager, official dating goddess

Android 0 Basics 7th: Take care of Android simulator and start the Sweet journey

Android 0 Basics 8th: HelloWorld, the starting point for my first trip

Android 0 Basics 9th: Android app, no code can be developed

Android 0 Basics Section 10th: Development IDE Big upgrade, finally ushered in Android Studio

Android 0 Basics Introductory Section 11th: Simple steps to take you to fly, run Android Studio project

Android 0 Basics 12th: Get familiar with the Android studio interface and start selling

Android 0 Basics 13th: Android Studio Configuration optimization to create a development tool

Android 0 Basics 14th: Using high-speed genymotion, stepping into the rocket era

Android 0 Basics Section 15th: Mastering the Android Studio project structure, sailing

Android 0 Basics Section 16th: Android User Interface Development overview

Android 0 Basics Section 17th: TextView Properties and Methods Daquan

Android 0 Basics Section 18th: EditText properties and how to use them

Android 0 Basics section 19th: Button usage explained

Android 0 Basics Section 20th: checkbox and RadioButton Usage Daquan

Android 0 Basics Section 21st: ToggleButton and switch usage Daquan

Android 0 Basics Section 22nd: ImageView's properties and methods Daquan

Android 0 Basics Section 23rd: ImageButton and Zoombutton use Daquan

Android 0 Basics Section 24th: Customize view simple to use to create your own controls

Android 0 Basics Section 25th: Simple and most commonly used linearlayout linear layouts

Android 0 Basics Section 26th: Two alignments, layout_gravity and gravity differ greatly

Android 0 Basics section 27th: Using padding and margin correctly

Android 0 Basics Section 28th: Easy to master relativelayout relative layout

Android 0 Basics 29th: Use tablelayout table layouts

Android 0 Basics 30th: Two minutes master Framelayout frame layout

Android 0 Basics Section 31st: absolutelayout absolute Layout with less

Android 0 Basics Section 32nd: New GridLayout Grid layout

Android 0 Basics section 33rd: Android Event Handling overview

Android 0 Basics Section 34th: Listening-based event handling in Android

Android 0 Basics Section 35th: Callback-based event handling in Android

Android 0 Basics Section 36th: Handling of Android system events

Android 0 Basics 37th: First Knowledge ListView

Android 0 Basics 38th: First Knowledge Adapter

Android 0 Basics section 39th: listactivity and custom list items

Android 0 Basics Section 40th: Customizing Arrayadapter

Android 0 Basics Section 41st: Using Simpleadapter

Android 0 Basics Section 42nd: Customizing Baseadapter

Android 0 Basics section 43rd: ListView Optimization and List End-to-end use

Android 0 Basics Section 44th: ListView Data Dynamic Update

Android 0 Basic Getting Started section 45th: Grid view GridView

Android 0 Basics section 46th: List Options Box spinner

Android 0 Basic Getting Started section 47th: AutoComplete text Box Autocompletetextview

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.