State Not Change Of Toggle Button
I have listview with toggle button when i click on toggal button and scroll down then state of the button will change to Off state Please do the replay
Solution 1:
use sharedpreference
to save the state of each toggle button and load the state from the sharedpreference
Like you can define a state of your toggle (which has unique id) in sharedpreference
Here in Custom adaptor defined shared preference value.
final ToggleButton tgl=(ToggleButton)row.findViewById(R.id.tglalertstatus);
tgl.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {
@OverridepublicvoidonCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
{
SharedPreferencescontact= context.getSharedPreferences(
"contact", 1);
editor = contact.edit();
editor.putInt("toggle"+tgl.getContentDescription().toString(), 1); // i set the content description for each toggle a unique string so it will work as a key for shared preference.
editor.commit();
}
else
{
SharedPreferencescontact= context.getSharedPreferences(
"contact", 1);
editor = contact.edit();
editor.putInt("toggle"+tgl.getContentDescription().toString(), 0);//i set the content description for each toggle a unique string so it will work as a key for shared preference.
editor.commit();
}
}
});
hope this will help.
Post a Comment for "State Not Change Of Toggle Button"