Android Autocompletetextview Control Basic Usage Example _android

Source: Internet
Author: User

This example describes the basic usage of the Android Autocompletetextview control. Share to everyone for your reference, specific as follows:

When the input part of the content will have related suggestions, similar to the Baidu hint information

1. Declare a autocompletetextview in the layout file

<autocompletetextview
    android:id= "@+id/autocomplete_country"
    android:layout_width= "Fill_parent"
    android:layout_height= "wrap_content"
    android:layout_marginleft= "5DP"
  />

2, the definition of a hint entry style, in the layout directory to establish list_item.xml files

<?xml version= "1.0" encoding= "Utf-8"?> <textview xmlns:android=
  "http://schemas.android.com/apk/" Res/android "
  android:layout_width=" fill_parent "
  android:layout_height=" Fill_parent "
  android: padding= "10DP"
  android:textsize= "16sp"
  android:textcolor= "#000" >
</TextView>

3, it needs to use Arrayadapter to provide data

public void Setautocompletetextview () {
  Autocompletetextview = (autocompletetextview) Findviewbyid ( R.id.autocomplete_country);
  Countries is an array that Autocompletetextview matches the contents of the array with the input of the user and then displays to prompt the user
  //r.layout.list_item to display the style
  of the content displayed by the hint message arrayadapter<string> arrayadapter = new Arrayadapter<string> (this, R.layout.list_item, COUNTRIES);
  Autocompletetextview.setadapter (Arrayadapter);
}

Note: Countries is an array type

4, the Autocompletetextview and Arrayadapter link up

For more information on Android-related content readers can view the site topics: "Android File Operation tips Summary", "Android programming development of the SD card operation Summary", "Android Development introduction and Advanced Course", "Android Resources Operating Skills summary", " Android View tips Summary and a summary of the use of Android controls

I hope this article will help you with the Android program.

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.