Android-based automatic text input recognition prompt and android Text Recognition

Source: Internet
Author: User

Android-based automatic text input recognition prompt and android Text Recognition

I believe everyone is familiar with the automatic identification tips, which can be seen everywhere in our lives. Today, let me briefly introduce how it is designed.

The so-called automatic identification input is based on the existing information entered by the user, prompting the user of possible values, so that the user can complete the input. On Android devices, this function can be divided into: AutoCompleteTextView and MultiAutoCompleteTextView. The former is a single automatic recognition, similar to a prompt in the input box of the search engine. The latter is automatically recognized for multiple values, similar to the email input box when sending an email. How are they used? Let's take a look at it.

First, layout files:

<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/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/plugin" tools: context = ". activityfive "> <AutoCompleteTextView android: id =" @ + id/acTextView "android: layout_width =" match_parent "android: layout_height =" wrap_content "android: hint =" Enter the name: "android: textColor =" #000 "android: maxLength =" 10 "/> <MultiAutoCompleteTextView android: id =" @ + id/macTextView "android: layout_below = "@ id/acTextView" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: hint = "enter the city:" android: textColor = "#000" android: maxLength = "20"/> </RelativeLayout>

Note: The android: hint attribute indicates the prompt text content. It automatically disappears when the focus is obtained in the input box.

Here is 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 us"}; @ Override protected void onCreate (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 = 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); // you can specify the number of characters entered to automatically match macTextView. setTokenizer (new MultiAutoCompleteTextView. commaTokenizer (); // sets the separator }}

 

The code is very simple, and there is no esoteric point. I believe you can understand it at a Glance. For some difficult points, I have added comments to hope they will be useful to you.

 

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.