How to make sure at least one CheckBoxPreference is selected
I have a PreferenceActivity
containing a number of CheckBoxPreference
开发者_C百科 and I want to make sure that at least one of them is selected, any suggestion on how to do it?
Thanks
I ended up registering the same instance of Preference.OnPreferenceChangeListener
on all my CheckBoxPreference
. The listener keeps a set with my CheckBoxPreference
and reacts when the user unchecks one, returning false if it's the only one checked.
Cant you use .setChecked(true) on the checkbox control
i.e.
// get the control final CheckBox chkRemember = (CheckBox) findViewById(R.id.checkbox);
// pull th evalue from your preferences strChecked = rwPref.readWriteUserSetting(DevDroidSLX.this, "Read", "CheckboxValueA" , "" );
if ( strChecked.equalsIgnoreCase("True"))
{
chkRemember.setChecked(true);
}
else
{
chkRemember.setChecked(false);
}
精彩评论