Android Automatic text box input recognition hint function code _android

Source: Internet
Author: User

Automatic prompt text box (Autocompletetextview) can enhance the user experience, shorten the user's input time (Baidu's search box is this effect).

I believe we are familiar with the automatic identification tips, in our life everywhere, today let me give you a brief introduction of how it is designed.

The so-called automatic recognition input is based on the user input of the existing information, for users to prompt the possible value, user-friendly completion of input. On Android devices This feature is divided into: Autocompletetextview and Multiautocompletetextview, the former as a single automatic recognition, similar to the Search engine input box prompts; the latter is automatically recognized for multiple values, Similar to the Mailbox entry box when you send a message. So how exactly do they use them? Now let's study together.

The first is the layout file:

 <relativelayout 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:paddingbottom=" @dimen/activity_vertical_margin "android:paddingleft=" @dimen/activity_horizontal_ Margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen/activity_vertical_ Margin "tools:context=".
Activityfive "> <autocompletetextview android:id=" @+id/actextview "android:layout_width=" Match_parent "
android:layout_height= "wrap_content" android:hint= "Please enter your name:" android:textcolor= "#000" android:maxlength= "ten"/> <multiautocompletetextview android:id= "@+id/mactextview" android:layout_below= "@id/actextview" Android:layout_ Width= "Match_parent" android:layout_height= "wrap_content" android:hint= "Please enter the city:" Android:textcolor= "#000" Android: Maxlength= "/>" </RELATIVELAYOUT> 

Note: The Android:hint property is the hint text content, automatically disappears when the input box gets focus

Here's our action:

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.ArrayAdapter;
Import Android.widget.AutoCompleteTextView;
Import Android.widget.MultiAutoCompleteTextView; public class Activityfive extends activity{private Autocompletetextview Actextview private Multiautocompletetextview
Mactextview;
Private String [] arr = {"abc", "ABX", "Abo", "BDC", "BDF"};
Private String [] brr = {"AB Beijing", "AB Nanjing", "Ab Tokyo", "BB Moscow", "BB uk", "BB USA"}; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated Method stub super.oncreate (savedins
Tancestate);
Setcontentview (r.layout.activity_five);
Actextview = (Autocompletetextview) Findviewbyid (R.id.actextview);
Mactextview = (Multiautocompletetextview) Findviewbyid (R.id.mactextview); arrayadapter<string> arradapt = new Arrayadapter<string> (this, Android. 
R.layout.simple_dropdown_item_1line, arr);
Actextview.setadapter (ARRADAPT); arrayadapter<string> brradapt = new Arrayadapter<string> (This, androiD.r.layout.simple_dropdown_item_1line, BRR);
Mactextview.setadapter (BRRADAPT); Mactextview.setthreshold (1);/set how many characters to enter to start automatically matching Mactextview.settokenizer (new Multiautocompletetextview.commatokenizer ());//Set Separator}}

The above is a small series to introduce the Android automatic text box input identification hint function code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.