Differences between autocompletetextview and multiautocompletetextview

Source: Internet
Author: User

Android provides a textview with the automatic prompt function. You can write several lines of code according to the built-in documentation and API demo to implement this function. However, the default thresh value is 2. Therefore, you must enter two or more characters by default to enable the automatic prompt function. Otherwise, autocompletetextview will not receive any prompts. Of course, you can use setthresh to set a prompt after entering at least a few characters, or you can set it in XML. Autocompletetextview matches all your strings as substrings, while multiautocompletetextview breaks down the strings you have already entered Based on the tokenizer you provided, the last few characters that meet the conditions are automatically prompted as substrings.

For example, if you set multiautocompletetextview. settokenizer (New multiautocompletetextview. commatokenizer ());

When you enter "it", it will prompt you Italy, and then you choose this string. In this case, the string in textview is "Italy", followed by ", it". In this case, the string is "Italy, it" in the textview ", in this case, multiautocompletetextview breaks down the "it" according to the configured Word Segmentation Method (commatokenizer) and matches it again. The prompt Italy is displayed. this is the origin of multi. Supports multiple word prompts. Of course, you must set the correct tokenizer ).

 

I. autocompletetextview

1. Introduction

An inherited fromEditViewOfThe editable text view can dynamically match the input content. For example, when Google search engine inputs text, it can display matching hot information based on the content.

2. Important Methods

Clearlistselection (): clears the selected list items.

Dismissdropdown (): If the drop-down menu is closed

Getadapter (): Get the adapter

 

Ii. multiautocompletetextview

1. Introduction

An inherited fromAutoCompleteTextViewOfThe editable text view effectively expands the text you type without entering the entire content. (If you enter a part of the content, the system will prompt the remaining part of the content ).

The user must provideMultiAutoCompleteTextView.TokenizerUsed to distinguish different substrings.

2. Important Methods

Enoughtofilter (): filter when the text length exceeds the threshold.

Validate mvalidation (): instead of verifying the entire text, this subclass method verifies each individual text mark

Settokenizer (multiautocompletetextview. tokenizer T): When the user is inputting, The tokenizer setting is used to determine the range of Text

The following are examples

Main. xml layout File

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <AutoCompleteTextView android:id="@+id/autoCompleteTextView"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>    <MultiAutoCompleteTextView android:id="@+id/multiAutoCompleteTextView"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/></LinearLayout>

Textviewactivity class

Package COM. ljq. activity; import android. app. activity; import android. OS. bundle; import android. widget. arrayadapter; import android. widget. autocompletetextview; import android. widget. multiautocompletetextview; public class textviewactivity extends activity {// Fujian jiudi Private Static final string [] cities = new string [] {"Fuzhou", "Xiamen", "nide ", "Putian", "Quanzhou", "Zhangzhou", "Longyan", "Sanming", "nanpi NG "}; private autocompletetextview = NULL; private multiautocompletetextview = NULL; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); autocompletetextview = (autocompletetextview) findviewbyid (R. id. autocompletetextview); multiautocompletetextview = (multiautocompletetextview) findview Byid (R. id. multiautocompletetextview); // create the adapter arrayadapter <string> adapter = new arrayadapter <string> (this, android. r. layout. simple_dropdown_item_1line, cities); autocompletetextview. setadapter (adapter); // set the number of characters entered and then prompt. The default value is 2 autocompletetextview. setthreshold (2); multiautocompletetextview. setadapter (adapter); multiautocompletetextview. setthreshold (2); // you must provide a multiautocompletetextview. tokenizer is used to differentiate Different substrings. Multiautocompletetextview. settokenizer (New multiautocompletetextview. commatokenizer ());}}

Running result

 

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.