Android Studio: Use of the AutoCompleteTextView control and androidstudio Control

Source: Internet
Author: User

Android Studio: Use of the AutoCompleteTextView control and androidstudio Control

If you enter the information we want to enter in the input box, other related prompts will appear. This effect is achieved in Android using AutoCompleteTextView. The AutoCompleteTextView control inherits from the TextView control and has its own properties:

AutoCompleteTextView common attributes
Android: completionHint Set the title of the prompt that appears in the drop-down menu
Android: completionThreshold Set the number of characters that the user must enter to display the prompt.
Android: dropDownHorizontalOffset Horizontal offset between text boxes in the drop-down menu. Align left with text box by default
Android: dropDownHeight Height of the drop-down menu
Android: dropDownWidth Width of the drop-down menu
Android: singleLine Single Row display
Android: dropDownVerticalOffset Vertical offset

I. Effects:


Ii. Code:

<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/activity_vertical_margin" android: paddingBottom = "@ dimen/plugin" tools: context = ". mainActivity "android: orientation =" vertical "> <TextView android: text =" Enter the Search Keyword: "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: textSize = "30dp"/> <AutoCompleteTextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: id = "@ + id/KeyWords" android: textSize = "30dp"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_gravity = "center_horizontal" android: text = "Search" android: textSize = "35dp"/> </LinearLayout>

Package com. example. lhb. autocompletetextview; import android. app. searchableInfo; import android. support. v7.app. actionBarActivity; import android. OS. bundle; import android. view. menu; import android. view. menuItem; import android. widget. arrayAdapter; import android. widget. autoCompleteTextView; public class MainActivity extends ActionBarActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); Search ();} private void Search () {String [] aut = new String [] {"Android", "Android software", "Android Project ", "Android Studio" }; ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, R. layout. abc_simple_dropdown_hint, aut); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById (R. id. keyWords); textView. setAdapter (adapter );}}


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.