CheckboxPreference onClick()

痴心易碎 提交于 2019-12-02 07:28:29

You could try something like:

final Preference otherpref = (Preference) findPreference("otherpref"); 
final Preference pref = (Preference) findPreference("checkbox");        
pPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

    public boolean onPreferenceClick(Preference preference) {
        otherPref.setSelectable(false);
        Toast.makeText(getBaseContext(), "Some text", Toast.LENGTH_SHORT).show();
        return true; 
    }
});

And disable your desired categories.

I have implemented my preference activity as a class which extends PreferenceActivity and implements OnSharedPreferenceChangeListener

public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Context context = getApplicationContext();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.registerOnSharedPreferenceChangeListener(this);
  }

  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    // Check the checkboxes
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!