Android study note 20: Automatically complete text box

Source: Internet
Author: User

In Android, autocompletetextview can automatically complete text input boxes, which is similar to Ajax in Web pages. When using this function, you must specify an adapter to set the complete text.

<? 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 prompt --> <! -- Android: dropdownhorizontaloffse: sets the horizontal offset of the drop-down list --> <autocompletetextview Android: Id = "@ + ID/auto" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: completionhint = "Please select your favorite song" Android: dropdownhorizontaloffset = "20dp" Android: completionthreshold = "1"/> <! -- Specify the number of words to be input and a response prompt --> </linearlayout>

Public class autocompletetextviewtest extends activity {// defines the 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"}; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // create an arrayadapter that encapsulates 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 adapteractv. setadapter (AA );}}

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.