How to enable a preference in my android application when other preference is disabled?

后端 未结 4 1414
既然无缘
既然无缘 2021-01-01 13:52

I have used PreferenceActivity to have preference in my android application. I want one preference say \"pref 2\" to be enabled when other preference say \"pref

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 14:27

    I don't think there's any out-of-the-box solution for it, i.e. an inverted dependancy attribute. But there's always the click-listener:

    preference1.setOnPreferenceClickListener(pref1_click);
    
    ....
    
    private OnPreferenceClickListener pref1_click = new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            preference2.setEnabled(!preference1.isChecked());
            return true;
        }
    }
    

提交回复
热议问题