2

I have a ListPreference with to items.

Now I would like to activate the EditTextPreference only if item2 is selected and deactivated if item1 is selected.

android:dependency=" " does not work

How can I do that?

I found this but I don't understand it: ListPreference dependency

Community
  • 1
  • 1
mosambers
  • 21
  • 1
  • 7

1 Answers1

0

There is a way to set the dependency of the list item

itemList = (ListPreference)findPreference("itemList");
itemList2 = (ListPreference)findPreference("itemList2");
itemList.setOnPreferenceChangeListener(new
Preference.OnPreferenceChangeListener() {
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    final String val = newValue.toString();
    int index = itemList.findIndexOfValue(val);
    if(index==3)
      itemList2.setEnabled(true);
    else
      itemList2.setEnabled(false);
    return true;
  }
});

you can change it according to your requirement

Tabish Hussain
  • 852
  • 5
  • 13
  • I linked to that answer... findPreferance is deprecated and I don't know how to adapt the code to my wishes. Can you help me? – mosambers Dec 06 '16 at 13:33