Android enables dynamic matching of input content Autocompletetextview and Multiautocompletetextview

Source: Internet
Author: User

Autocompletetextview
1. Function:
Dynamically match the input content, such as Baidu search engine when the input text can be displayed according to the content of popular information matching.
2. Unique attributes:
Android:completionthreshold set How many characters are entered automatically when you match

Using Autocompletetextview to implement automatic matching of input content
Private Autocompletetextview Actextview;
Initializing the control
Actextview = (Autocompletetextview) Findviewbyid (R.ID.AUTOCOMPLETETEXTVIEW1);
Initialize the data source (the res array in the code adds some more)
Private string[] res = new string[] {"Moon", "Month", "Moonlight", "Moonlight Poet"};
Create an adapter (use Arrayadapter here)
arrayadapter<string> adapter = new Arrayadapter<string> (this, Android. R.layout.simple_expandable_list_item_1, RES);
The adapter is bound to the current Autocompletetextview (via the. Setadapter () method)
Actextview.setadapter (adapter);
The contents of adapter appear in Activity_main.xml settings when you enter how many characters
android:completionthreshold= "1"

Multiautocompletetextview
1. function
Can support the selection of multiple values (in the case of multiple input), separated by a delimiter, and the value of each value is checked again automatically to match, can be used in text messaging, e-mail to select the type of contact.
2. Unique attributes:
Android:completionthreshold set How many characters are entered automatically when you match
3. Set the delimiter
Mtxt.settokenizer (New Multiautocompletetextview.commatokenizer ());

Using Multiautocompletetextview to implement automatic matching of input content
The exact steps are similar to Autocompletetextview.
Set the delimiter (set with a comma delimiter)
Mactextview.settokenizer (New Multiautocompletetextview.commatokenizer ());

<LinearLayoutxmlns: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:orientation= "vertical"    >    <AutocompletetextviewAndroid:id= "@+id/autocompletetextview1"Android:completionthreshold= "1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter the keywords you want to search"        >        <Requestfocus/>    </Autocompletetextview>    <MultiautocompletetextviewAndroid:id= "@+id/multiautocompletetextview1"Android:completionthreshold= "1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:ems= "Ten"Android:hint= "Please enter keywords (multiple, comma delimited)"         />    </LinearLayout>
Activity_main.xml
 PackageCom.example.autocompletetextviewandmulti;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.support.v7.app.ActionBar;Importandroid.support.v4.app.Fragment;ImportAndroid.os.Bundle;ImportAndroid.view.LayoutInflater;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.AutoCompleteTextView;ImportAndroid.widget.MultiAutoCompleteTextView;ImportAndroid.os.Build; Public classMainactivityextendsactionbaractivity {PrivateAutocompletetextview Actextview; PrivateMultiautocompletetextview Mactextview; Privatestring[] Res =Newstring[] {"Apple", "banana", "China", "delicious", "eight", "Fight", "good",            "Hello", "intelligence", "just", "kilometer", "like",            "Moon", "Month", "Moonlight", "Moonlight Poet",            "Night", "OK", "pear", "queue", "Ring", "stack", "tail",            "Unique", "very", "Week", "x-men", "Yellow", "zero"            }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); Actextview=(Autocompletetextview) Findviewbyid (R.ID.AUTOCOMPLETETEXTVIEW1); Arrayadapter<String> adapter =NewArrayadapter<string> ( This, Android.        R.layout.simple_expandable_list_item_1, RES);                Actextview.setadapter (adapter); Mactextview=(Multiautocompletetextview) Findviewbyid (R.ID.MULTIAUTOCOMPLETETEXTVIEW1);        Mactextview.setadapter (adapter); Mactextview.settokenizer (NewMultiautocompletetextview.commatokenizer ()); }}
Mainactivity.java

Effect:

Android enables dynamic matching of input content Autocompletetextview and Multiautocompletetextview

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.