Android--Spinner && Autocompletetextview

Source: Internet
Author: User

Spinner drop-down selection box

Android provides us with a spinner control, which is primarily a list of spinner located Android.widget package, each time only the user selected elements, when the user clicks again, the selection list will pop up for the user to select, and the selection list of elements also from the adapter. Spinner is a subclass of the view class.

 PackageCom.yydcdut.spinnerstudy;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.widget.AdapterView;ImportAndroid.widget.AdapterView.OnItemClickListener;ImportAndroid.widget.AdapterView.OnItemSelectedListener;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.Spinner;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {PrivateSpinner Spinner; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Spinner=(Spinner) Findviewbyid (R.id.spiiner); Arrayadapter<String> adapter =NewArrayadapter<string>(Getapplicationcontext (), Android.        R.layout.simple_spinner_item); Adapter.setdropdownviewresource (Android.        R.layout.simple_spinner_dropdown_item); Adapter.add ("123"); Adapter.add ("321"); Adapter.add ("123321");        Spinner.setadapter (adapter); Spinner.setonitemselectedlistener (NewOnitemselectedlistener () {@Override Public voidOnitemselected (adapterview<?>Parent, view view,intPositionLongID) {Spinner spinner1=(Spinner) parent; String content= (String) spinner1.getitematposition (position);//gets the data at the specified location of the list data associated with the spinnerToast.maketext (Getapplicationcontext (),"Position-->" + position + "content--" +content, Toast.length_long). Show (); } @Override Public voidOnnothingselected (adapterview<?>parent) {                //TODO Auto-generated method stubs            }        }); }}

Next we pass the replacement Adapter.setdropdownviewresource (Android. R.layout.test_list_item); The XML parameter inside to look at the popup style, the specific can refer to: http://hi.baidu.com/ihsauqaxblbdmwq/item/62fa237f935a6a580d0a0780

Autocompletetextview

 Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); String[] Names= {"Z11", "Z22", "Z33", "A44", "A55" }; Autocompletetextview Auto=(Autocompletetextview) Findviewbyid (R.id.auto); Arrayadapter<String> adapter =NewArrayadapter<string> ( This, Android.        R.layout.simple_dropdown_item_1line, names);    Auto.setadapter (adapter); }}

Autocompletetextview is the content that implements dynamic match input. Google search engines, for example, can display popular information that matches content as they enter text.

Although Autocompletetextview is not a common Android control, but its practicality is very strong, specific use can refer to Apidemos, for basic usage, it has a very detailed description. But these examples are far from satisfying our needs, and here are a few examples of attributes that are not covered.

    • Completionthreshold: Its value determines that you enter at least a few characters in the Autocompletetextview, which will have the ability to automatically prompt. Also, the default is up to 20 prompts.
    • Dropdownanchor: Its value is the ID of a view, and when specified, Autocompletetextview will pop up the auto prompt in this view.
    • Dropdownselector: should be set to automatically prompt the background color and so on, have not tried, pending further research.
    • DropDownWidth: Sets the width of the auto-prompt list.

I'm the dividing line of the king of the Land Tiger.

Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01

Spinner learning. zip

Autocompletetextview Learning. zip

Reprint Please specify source: Http://www.cnblogs.com/yydcdut

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.