The use of Autocompletetextview in Android

Source: Internet
Author: User

The final effect is as follows:

The Main.xml code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent "    android:o rientation= "vertical" >    <autocompletetextview        android:id= "@+id/autocompletetextview1"        Android : layout_width= "match_parent"        android:layout_height= "wrap_content"        android:completionhint= "Please choose your favorite songs"        android:completionthreshold= "1"        android:dropdownhorizontaloffset= "20DP"        android:ems= "Ten        " android:text= "Autocompletetextview" >        <requestfocus/>    </autocompletetextview></ Linearlayout>

The Java code is:

Package Android.demo;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.drawable.bitmapdrawable;import Android.os.Bundle;import Android.view.motionevent;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.view.ontouchlistener;import Android.widget.arrayadapter;import Android.widget.AutoCompleteTextView; Import Android.widget.button;import Android.widget.imageview;public class Androiddemo5activity extends Activity {// Defines a string array as a hint of text string[] books = new string[] {"Rollen", "Rollenholt", "Rollenren", "roll"}; @Overrideprotected void Oncrea Te (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.main);//Create a Arrayadapter encapsulated array arrayadapter<string> av = new arrayadapter<string> (this,android. R.layout.simple_dropdown_item_1line, books); Autocompletetextview auto = (Autocompletetextview) Findviewbyid (r.id.autocompleteTEXTVIEW1); Auto.setadapter (AV);}} 

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.