Automatic Filling Based on AutoCompleteTextView in Android

Source: Internet
Author: User

Now we will use Baidu or Google to search for information on the Internet. When we enter one or two words in the input box, we will automatically prompt the information we want.AndroidYesAndroidOfAutoCompleteTextView WidgetMatchingArrayAdapterSimilar DesignGoogleSearch for the effect of the prompt.

First inLayoutLayout oneAutoCompleteTextView WidgetAnd then put this string array intoArrayAdapter, And finally useAutoCompleteTextView. setAdapterMethod, you can makeAutoCompleteTextViewProvides the automatic prompt function. For example, you only need to enterABWill automatically includeABList of all strings.Copy codeThe Code is as follows: public class MainActivity extends Activity {

Private AutoCompleteTextView actv;
Private static final String [] autoStrs = new String [] {"a", "abc", "abcde "};

@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Actv = (AutoCompleteTextView) findViewById (R. id. actv );
ArrayAdapter adapter = new ArrayAdapter (this, android. R. layout. simple_dropdown_item_1line, autoStrs );
Actv. setAdapter (adapter );
}

@ Override
Public boolean onCreateOptionsMenu (Menu menu) {getMenuInflater (). inflate (R. menu. main, menu );
Return true;
}
}

Copy codeThe Code is as follows: <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">

<AutoCompleteTextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: id = "@ + id/actv"
Android: completionThreshold = "1"/> <! -- Set to start matching only by entering one word. -->

</LinearLayout>

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.