当我点击切换按钮并向下滚动然后按下按钮的状态将变为关闭状态时,我有切换按钮的列表视图 请进行重播
答案 0 :(得分:0)
使用sharedpreference
保存每个切换按钮的状态并从sharedpreference
您可以在共享偏好
中定义切换状态(具有唯一ID)这里在Custom adapter中定义了共享首选项值。
final ToggleButton tgl=(ToggleButton)row.findViewById(R.id.tglalertstatus);
tgl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
{
SharedPreferences contact = 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
{
SharedPreferences contact = 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();
}
}
});
希望这会有所帮助。