android - Explain Shared Preferences for Different Checkboxes -
i'm starting use shared preferences allow me save state of checkbox when leaving application. i've gotten work dawned on me maybe save preference checkboxes unless make preference. have make shared preference each checkbox reference?
code right now. know check or uncheck both checkboxes depending leave them @ because reference same preference.
checkbox checkbox = (checkbox) findviewbyid(r.id.description); checkbox checkbox1 = (checkbox) findviewbyid(r.id.description1); sharedpreferences sharedpref = getsharedpreferences("mypref", mode_private); boolean checked = sharedpref.getboolean("checked", false); checkbox.setchecked(checked); checkbox1.setchecked(checked);
my check box handler looks this
if(tmpchkbox.ischecked()) { tmpchkbox.setbackgroundcolor(color.blue); sharedpreferences sharedpref = getsharedpreferences("mypref", mode_private); sharedpref.edit().putboolean("checked", true).commit(); } else { tmpchkbox.setbackgroundcolor(color.red); sharedpreferences sharedpref = getsharedpreferences("mypref", mode_private); sharedpref.edit().putboolean("checked", false).commit(); }
so need rename string references within 1 shared preference? sharedpref.edit().putboolean("checked", false).commit();
make 1 different check changed "checked" "checked1"?
Comments
Post a Comment