Use of Android Aoutcompletetextview controls

Source: Internet
Author: User

Aoutcompletetextview

Function:1> dynamically match the input content, such as Baidu search engine when you enter text can be displayed according to the content of popular information matching

2> Unique properties: android:completionthreshold= "2" <!--set how many characters to automatically match

Layout layouts with automatic matching

<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"

Tools:context= ". Mainactivity ">

<autocompletetextview
Android:id= "@+id/autocompletetextview"

Android:layout_width= "Match_parent"

android:layout_height= "Wrap_content"

Android:hint= "Please enter a keyword to query"

Android:completionthreshold= "2" />

Automatic matching of class files

Package Cn.androidstudy.demo;

Import Android.os.Bundle;

Import android.app.Activity;

Import Android.view.Menu;

Import Android.widget.ArrayAdapter;

Import Android.widget.AutoCompleteTextView;

public class Mainactivity extends Activity {

Private Autocompletetextview Actextview;

Private string[] res = {"Shanghai", "Beijing", "tianjing", "Sichuan", "Yibin", "Sichuanjianzhuzhiyijishuxueyuan"};

@Override protected void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.activity_main);

/** * 1. Initialization control: actextview= (Autocompletetextview) * FINDVIEWBYLD (R.id.autocompletetextview)

* 2. Requires an adapter: Arrayadapter * <String> adapeter = new Arrayadapter<string> (this, * Android. R.layout.simple_expandable_list_item_1, RES);

* 3. Initialize the data source---this data source automatically matches the contents of the text box private string[] res = {"Shanghai", "Beijing", * "tianjing", "Sichuan", "Yibin", "Sichuanjian Zhuzhiyijishuxueyuan "};

* 4. Bind Adapeter and Aoutcompletetextview: Actextview.setadapter (Adapeter); *  */

Actextview = (Autocompletetextview) Findviewbyid (R.id.autocompletetextview);

arrayadapter<string> adapeter = new Arrayadapter<string> (this, Android. R.layout.simple_expandable_list_item_1, RES);

Actextview.setadapter (Adapeter); }

@Override public boolean Oncreateoptionsmenu (Menu menu) {

Inflate the menu; This adds items to the action bar if it is present.

Getmenuinflater (). Inflate (R.menu.main, menu); return true;

} }

Use of Android Aoutcompletetextview controls

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.