I want to store in SharedPreferences if the toggle button is Checked or uncheck.
toggle.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
if(isChecked){
SharedPreferences.Editor editor = getSharedPreferences("SharedPrefName", MODE_PRIVATE).edit();
editor.putBoolean("check", true);
editor.commit();
}
else {
SharedPreferences.Editor editor = getSharedPreferences("SharedPrefName", MODE_PRIVATE).edit();
editor.putBoolean("nocheck", false);
editor.commit();
}
}});
But when I test this, it is always set to check
in OnCreate() I added this:
SharedPreferences preferences = getSharedPreferences("SharedPrefName", MODE_PRIVATE);
boolean value1 = preferences.getBoolean("check", true);
if (value1 = sharedPrefs.getBoolean("check", true)){
psw.setChecked(value1);
}else {
psw.setChecked(false);
}