开发者

How to make sure at least one CheckBoxPreference is selected

开发者 https://www.devze.com 2023-03-23 12:58 出处:网络
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?

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);
      }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号