Android implements auto-complete text box in search box

Source: Internet
Author: User

Android implements the search box to automatically complete the text box in the XML file code as follows:
1<?xml version="1.0"encoding="Utf-8"?>2<LinearLayout3Xmlns:android="http://schemas.android.com/apk/res/android"4android:orientation="Vertical"5Android:layout_width="fill_parent"6android:layout_height="fill_parent">7 8<Autocompletetextview9Android:id="@+id/myautocompletetextview"TenAndroid:layout_width="fill_parent" Oneandroid:layout_height="wrap_content"/> A  -</LinearLayout>
The Java file code is as follows:
1 Package Com.example.sample_5_1;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 ImportAndroid.widget.ArrayAdapter;6 ImportAndroid.widget.AutoCompleteTextView;7 8PublicclassAutocompleteactivity extends Appcompatactivity {9private static final string[] MyStr =New string[]{Ten             "Vae","Victory","Vision","Virtue","Vital" One     }; A @Override - protected void OnCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); the Setcontentview (r.layout.activity_auto_complete); -arrayadapter<string> AA = new arrayadapter<string> (//Create an adapter -This,//Context - Android. R.layout.simple_dropdown_item_1line, +//use the simple layout that comes with Android -MYSTR); //Resource Array +Autocompletetextview Myautocompletetextview = A (Autocompletetextview) Findviewbyid (R.id.myautocompletetextview); at//get a reference to a control -Myautocompletetextview.setadapter (AA); //setting up the adapter -Myautocompletetextview.setthreshold (1); //define the number of characters that require user input -     } -}
as follows: (Enter a V to automatically prompt for all content starting with V)

Android implements auto-complete text box in search box

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.