i have a checkbox in my app and i want to know if its possible to for the app to remember the last state of the checkbox i mean when the checkbox is checked and the app is closed when the app is opened again the checkbox is still checked same with unchecked.
this is how i did it.
i have this code on OnResume
@Override
protected void onResume() {
super.onResume();
if(checkbox.equals(true)){
checkbox.setChecked(true);
}else{
checkbox.setChecked(false);
}
}
and this is my onchecklistener
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if(checkbox.isChecked()){
checkbox.setChecked(true);
publicvar.displayMessage(Login.this, "check", 0);
}else{
checkbox.setChecked(false);
publicvar.displayMessage(Login.this, "uncheck", 0);
}
}
});
unfortunately it didn't work