Automatic text input recognition tips for Android

Source: Internet
Author: User

I believe that we are familiar with automatic identification tips, in our lives 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 values, user-friendly completion of input. On Android Devices This function is divided into:Autocompletetextview and Multiautocompletetextview, the former is a single automatic recognition, similar to the search engine input box prompt The latter is automatically recognized for multiple values, similar to the mailbox input box when the message was sent. So how do they both use it? Let's learn it 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 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 City:"Android:textcolor= "#000"Android:maxlength= "/></relativelayout>"

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

Here's our Action:

Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.AutoCompleteTextView;ImportAndroid.widget.MultiAutoCompleteTextView; Public classActivityfiveextendsactivity{PrivateAutocompletetextview Actextview; PrivateMultiautocompletetextview Mactextview; PrivateString [] arr = {"abc", "ABX", "Abo", "BDC", "BDF"}; PrivateString [] brr = {"AB Beijing", "AB Nanjing", "Ab Tokyo", "BB Moscow", "BB uk", "BB USA"}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub        Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_five); Actextview=(Autocompletetextview) Findviewbyid (R.id.actextview); Mactextview=(Multiautocompletetextview) Findviewbyid (R.id.mactextview); Arrayadapter<String> arradapt =NewArrayadapter<string> ( This, Android.         R.layout.simple_dropdown_item_1line, arr);        Actextview.setadapter (ARRADAPT); Arrayadapter<String> brradapt =NewArrayadapter<string> ( This, Android.        R.layout.simple_dropdown_item_1line, BRR);        Mactextview.setadapter (BRRADAPT); Mactextview.setthreshold (1);//set how many characters to enter to start auto-matchMactextview.settokenizer (NewMultiautocompletetextview.commatokenizer ());//Set delimiter    }}

The code is very simple, there is no esoteric place, I believe you can understand, for some bad understanding of the place, I have added a note, I hope to be useful to you.

Automatic text input recognition tips for Android

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.