java - Trouble setting SharedPreferences, not sure of issue -
i want following code save data sharedpreferences file:
// assign external resources savebutton = (button)findviewbyid(r.id.button6); // set listener interact button savebutton.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { sharedpreferences allmaps = getsharedpreferences("allmaps", context.mode_private); sharedpreferences.editor editor = allmaps.edit(); sharedpreferences currentmap = getsharedpreferences("currentmap", context.mode_private); string currentmapname = currentmap.getstring("mapname", ""); map<string,?> keys = allmaps.getall(); for(map.entry<string,?> entry : keys.entryset()){ //delete objects currentmap mapname if (entry.getkey().tostring().contains(currentmapname)) { editor.remove(entry.getkey().tostring()); } } //put mapname here editor.putstring("mapname" + currentmapname, currentmapname); //put objects arrays allmaps //need reference of mindmapview view object mindmapview mindmapview = (mindmapview)findviewbyid(r.id.mindmapview); (int = 0; < mindmapview.mindmaparraylistlabels.size(); i++) { editor.putstring(currentmapname + "label" + i, mindmapview.mindmaparraylistlabels.get(i)); } (int = 0; < mindmapview.mindmaparraylistimgs.size(); i++) { editor.putint(currentmapname + "image" + i, mindmapview.mindmaparraylistimgs.get(i)); } editor.commit(); } });
for reason not working. reference file in other places, seems work fine in areas.
you can use publicsharedpreferences class in this answer. worked perfect me. hope helps.
Comments
Post a Comment