I have to two Class in my App
- Setting(for saving the settings)
- main Class
I defined the Toggle button and check box in Setting class for On and Off.
now when I call the setting class and from the main class and the change the checked state of Toggle Button and Check Box and the return to main class and if I again call the Setting class the checked state of the Toggle button and check box is not change it come back to it original state please help
My CODE:
yes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(((CheckBox) v).isChecked())
sound.toggle();
}
});
sound.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
Log.v("CheckBoxActivity", (isChecked ? "checked" : "not checked"));
}
});
}
public void doClick(View view) {
Log.v("CheckBoxActivity", ((CheckBox) view).isChecked() ? "checked" : "not checked");
}
This probably will be the problem as each time your activity starts,it would take default selection state for the components.
To achieve you goal,you need to store what state you need for a toggle button and checkbox.And then you will have to set the according state of the same each time you load activity,that mean in onCreate() just before you start defining onClick() on those components.
You can use SharedPreference object to store state at a time and use the same in onCreate() of you activity to set stored states of toggle button and checkboxes.