samedi 21 janvier 2017

How to save and retrieve value / selection of a Check Box in Android shared preferences? [duplicate]

I am trying to save and retrieve information the user enters in a edit box and the selections made on check box. I have managed to get the edit box working but can't seem to figure out how to do it for the Check box.

This is for the Edit Box and it works fine to save the information.

editor.putString("saveName", name.getText().toString());

But thos doesn't. for the Checkbox editor.putBoolean("saveChoice1", choice1.isChecked());

This is for the Edit Box and it works fine to read the information. editor.putString("saveName", name.getText().toString());

But these don't... for the Spinner and Checkbox choice1.setSelected(sharedPref.getBoolean("saveChoice1", false));

I have spent a lot of time doing this and would really appreciate any help!




Aucun commentaire:

Enregistrer un commentaire