How to do opposite of of preference attribute android:dependency?

后端 未结 5 1872
抹茶落季
抹茶落季 2020-12-07 18:36

Is there XML attribute that does the exact opposite of android:dependency?

What I would like the dependent preference to be enabled when the other is N

5条回答
  •  一生所求
    2020-12-07 19:15

    This is my code sample for doing this from code and not XML.

      String eitherKey = "either";
      String orKey = "or";
      CheckBoxPreference either = new CheckBoxPreference(this);
      either.setKey(eitherKey);
      either.setTitle("Either");
      either.setSummary("It is either one or");
      either.setDefaultValue(false);
      either.setDisableDependentsState(true);
      inlinePrefCat.addPreference(either);
    
      try
      {
         //Crossfade Time
         CheckBoxPreference or = new CheckBoxPreference(this);
         or.setKey(orKey);
         or.setTitle("Or");
         or.setSummary("the other");
         inlinePrefCat.addPreference(or);
         or.setDependency(eitherKey);
      }
      catch (Exception e)
      {
      }
    

提交回复
热议问题