限制 Android 首选项中的复选框数量

Limit number of checkboxes in Android Preferences

我一直在想办法限制我的偏好设置中可勾选框的数量 activity。

我正在使用首选项 activity 创建多个 select 选项,但一次只想让 5 个 select 编辑。因此,一旦第五个 selected,其他的就会变灰。但是,当其中一个脱select时,其余的都不会变成灰色。

我遇到的唯一问题是我不知道如何将 OnClickListener 设置到任何首选项复选框或类似的东西。

大家有什么想法。

假设您要将侦听器放在一个复选框上,这是假设完成的工作。

final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
checkbox_id.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

   @Override
   public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {

     //do whatever you wish to do when that checkbox is checked

   }
}
); 

实际上,我想我明白了。我要找的是:

final CheckBoxPreference myBox = CheckBoxPreference)findPreference("CheckBoxItem");