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