Android Dynamic Add spinner (implemented within. java files) Implementation changes spinner text attributes

Source: Internet
Author: User


Adding spinner controls dynamically

New Spinner (this); String []items={"itself defines the array to display"=new my_spinneradapter (this, Android. R.layout.simple_spinner_item, items); Array_adapter.setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item); S.setadapter (array_adapter);

Overwrite Arrayadapter with inner class
ClassMy_spinneradapterextendsArrayadapter<string>{context context; String [] objects; PublicMy_spinneradapter (Context context,intTextviewresourceid, string[] items) { Super(context, Textviewresourceid, items); This. Context =context; This. Objects =items; } @Override PublicView Getdropdownview (intposition, View Convertview, ViewGroup parent) { //This function modifies the font size and mode of the selected part after the spinner click . if(Convertview = =NULL) {Layoutinflater inflater=Layoutinflater.from (context); Convertview= Inflater.inflate (Android. R.layout.simple_spinner_dropdown_item, parent,false); } //The Text1 used here can be copied directly without having to re-name it or you might not find it. The text box is the system defaultTextView TV =(TextView) Convertview.findviewbyid (Android. R.ID.TEXT1); Tv.settext (Objects[position]); Tv.settextsize (18);//The setting of display text is implemented herereturnConvertview; } @Override PublicView GetView (intposition, View Convertview, ViewGroup parent) { //This function modifies the size of the font displayed on the screen after selecting something in spinner if(Convertview = =NULL) {Layoutinflater inflater=Layoutinflater.from (context); Convertview=Inflater.inflate (Android. R.layout.simple_spinner_item, parent,false); } //The Text1 used here can be copied directly without having to re-name it or you might not find it. The text box is the system defaultTextView TV =(TextView) Convertview.findviewbyid (Android. R.ID.TEXT1); Tv.settext (Objects[position]); Tv.settextsize (18); returnConvertview; } }

Android Dynamic Add spinner (implemented within. java files) Implementation changes spinner text attributes

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.