java - Saving the state of a single spinner with different uses -
please have spinner in customadapterclass extends arrayadapter. want save state of spinner when activity destroyed. 1 spinner appears in listview. have searched see when there more 1 spinner, each having it's own id. how achieve please. here code
public class customlistadapterforcgpa extends arrayadapter<string> implements adapterview.onitemselectedlistener { linearlayout colorlayout; textview usergpscoreuneditable; spinner spinnerforgradepoints; public string mathsubject= "mathematics"; public string chemsubject = "chemistry"; public string physicssubject = "physics"; public string biologysubject = "biology"; public string gssubject = "general studies"; public string cscsubject = "csc"; sharedpreferences sharedpreferences; sharedpreferences.editor editor; public customlistadapterforcgpa(context context, arraylist<string> subjects) { super(context, r.layout.custom_list_view_cgpa, subjects); } @override public void onitemselected(adapterview<?> adapterview, view view, int i, long l) { } @override public void onnothingselected(adapterview<?> adapterview) { } @nonnull @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater layoutinflater = layoutinflater.from(getcontext()); view customview = layoutinflater.inflate( r.layout.custom_list_view_cgpa,parent,false); string singlesubject = getitem(position); textview singletext = (textview) customview.findviewbyid(r.id.listsubjectsmycoursescgpa); colorlayout = (linearlayout)customview.findviewbyid(r.id.colorforsubjectscgpa); usergpscoreuneditable = (textview)customview.findviewbyid(r.id.usergpscoreuneditable); spinnerforgradepoints = (spinner)customview.findviewbyid(r.id.spinnerforgradepointcgpa); arrayadapter<string> gradepointadapter = new arrayadapter<string>(getcontext(), android.r.layout.simple_spinner_dropdown_item, tabfirstsemestermycgpa.usersubjectgrade); spinnerforgradepoints.setadapter(gradepointadapter); spinnerforgradepoints.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> adapterview, view view, int i, long l) { string selecteditem = adapterview.getitematposition(i).tostring(); if (selecteditem.equals("a")) { toast.maketext(getcontext(), "you clicked a", toast.length_short).show(); }else if ( selecteditem.equals("b")) { toast.maketext(getcontext(), "you clicked b", toast.length_short).show(); }else if ( selecteditem.equals("c")) { toast.maketext(getcontext(), "you clicked c", toast.length_short).show(); }else if ( selecteditem.equals("d")) { toast.maketext(getcontext(), "you clicked d", toast.length_short).show(); }else if ( selecteditem.equals("e")) { toast.maketext(getcontext(), "you clicked e", toast.length_short).show(); }else if ( selecteditem.equals("f")) { toast.maketext(getcontext(), "you clicked f", toast.length_short).show(); } } @override public void onnothingselected(adapterview<?> adapterview) { } }); singletext.settext(singlesubject); colorlayout.setbackgroundcolor(usercourseselection2.usersubjectslistcolor.get(position)); return customview; } }
in pure java save state static field. value persist after activity destroyed because belongs class, not instance. should work same in android.
Comments
Post a Comment