Android auto-complete text box

Source: Internet
Author: User
In Android, autocompletetextview can automatically complete text input boxes, which is a bit like Ajax in Web pages. When using this function, you need to specify an adapter to set the completion.

<? XML version = "1.0" encoding = "UTF-8" ?>
< Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android"
Android: Orientation = "Vertical"
Android: layout_width = "Fill_parent"
Android: layout_height = "Fill_parent"
>
<! -- Define an Automatic completion text box, specify a character to input and then prompt -->
<! -- Android: dropdownhorizontaloffse -->
< Autocompletetextview
Android: ID = "@ + ID/auto"
Android: layout_width = "Fill_parent"  
Android: layout_height = "Wrap_content"  
Android: completionhint = "Select your favorite song"
Android: dropdownhorizontaloffset = "20dp"
Android: completionthreshold = "1" /> <! -- Specifies the number of words to be entered and a response prompt is displayed. -->

</ Linearlayout > Public Class Autocompletetextviewtest Extends Activity
{
// Define a string array as the prompt text
String [] books = New String [] {
"Sun Yanzi-Hey Jude ",
"Sun Yanzi-the moment ",
"Sun Yanzi-tonight I feel close to you ",
"Sun Yanzi-leave me alone"
};
@ Override
Public Void Oncreate (bundle savedinstancestate)
{
Super . Oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
// Create an arrayadapter and encapsulate the Array
Arrayadapter <string> AA = New Arrayadapter <string> (
This ,
Android. R. layout. simple_dropdown_item_1line,
Books );
Autocompletetextview ACTV = (autocompletetextview)
Findviewbyid (R. Id. Auto );
// Set Adapter
ACTV. setadapter (AA );
}
}

URL:Http://greatverve.cnblogs.com/archive/2012/01/04/android-auto-complete.html

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.