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