android - How to persist the state of switches within a List view -
this first attempt @ using list views , have created list view containing switches. whenever navigate away activity state of switches reset default value. list view contains 4 switches , many of answers have came across deal problem of switches resetting state when out of view.
i have thought creating array , storing state of each switch , loading state when user navigates activity. have advice how best achieve this?
public view getview(final int position, view convertview, viewgroup parent) { view view; if (convertview == null) { view = minflater.inflate(r.layout.options_list_item, parent, false); } else { view = convertview; } symbols m1 = getitem(position); switch optionsswitch = (switch) view.findviewbyid(r.id.switch2); optionsswitch.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked && position == 0) { state = true; } else { state = false; } } }); return view; }
there no best way achieve thoughts great, infact best judge know best fit design model , app design etc,
but persist data through talked sharedpreferences, disk or in heap memory stated.
hope helps
Comments
Post a Comment