Use Autocompletetextview in Android to enable auto-prompt function

Source: Internet
Author: User

Use Autocompletetextview in Android to enable auto-prompt function

In the Java document pre-set the need to prompt the string, the default is to enter two characters when the reminder, but can be used in the Java fileSetthreshold ()Method implementation change reminder is the number of characters entered, but the text of the reminder needs to be pre-matchedattached code:XML file:<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:orientation = "vertical"
tools:context = ". Mainactivity " >
     <TextView        Android:layout_width= "Fill_parent"        Android:layout_height= "Wrap_content"        Android:text= "Hello" />
 
    <Autocompletetextview        Android:id= "@+id/autocomplete"        Android:layout_width= "Fill_parent"        Android:layout_height= "Wrap_content" >    </Autocompletetextview > </LinearLayout> java files: Package Com.just;  Import Android.os.Bundle; Import android.app.Activity; Import Android.widget.ArrayAdapter; Import Android.widget.AutoCompleteTextView;  Public class mainactivity extends Activity {         Private Static Final string[] Autostr = New string[] { "a" , "ABC" , "ABCD" ,                      "ABCDE", "ABCdef" };         @Override        protected void onCreate (Bundle savedinstancestate) {               Super. OnCreate (savedinstancestate);Setcontentview (r.layout. Activity_main);arrayadapter<?> adapter = New arrayadapter<object> ( This,Android. R.layout. Simple_dropdown_item_1line, Autostr );Autocompletetextview Myautoview = (autocompletetextview) Findviewbyid (r.id. AutoComplete );Myautoview.setthreshold (3);Myautoview.setadapter (adapter);        } }PS: When using a new window, you must use adapter to achieve

Use Autocompletetextview in Android to enable auto-prompt function

Related Article

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.