0

it is possible set android:enabled="false" of EditTextPreference this is by default when user check the checkboxPreference if user click then EditTextPreference enable(true).. if uncheck then it will go enable(false)

Image

this is the problem..

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
Ahsan Saeed
  • 41
  • 1
  • 2
  • 9

2 Answers2

0

You can do it programetically in your PreferenceFragment

public class PreferenceFragment extends android.preference.PreferenceFragment

use this code: to programetically enable/disable the checkboxes..

  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        pref1 = (CheckBoxPreference) getPreferenceManager().findPreference("bookATrainer");
        pref2 = (CheckBoxPreference) getPreferenceManager().findPreference("cancelBooking");

        pref1.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                if (pref1.isChecked()) {
                    pref1.setChecked(false);
                } else {
                    pref2.setChecked(true);
                }
                return true;
            }

        });
        pref2.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                if (pref2.isChecked()) {
                    pref2.setChecked(false);
                } else {
                    pref1.setChecked(true);
                }
                return true;
            }

        });
    }
}
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
  • can we do this in MainActivity extands AppCompatActivity?? – Ahsan Saeed Apr 21 '17 at 20:55
  • in your activity onCreate call the preference fragment using: `android.app.FragmentManager fm = getFragmentManager(); fm.beginTransaction().replace(R.id.content_frame, new PreferenceFragment()).commit();`... – rafsanahmad007 Apr 21 '17 at 21:06
  • [Rafsan Ahmed Bhai](http://stackoverflow.com/users/6139861/rafsanahmad007) this code i have done.. but still i want to enable false. when user click on setting and true the CheckBoxPreference (cancelBooking) then this EditTextPreference will be true or visible.. – Ahsan Saeed Apr 22 '17 at 07:37
0

Please reword your question but it sounds like you want to enable or disable an option based on a checkbox. Put the dependency under hourBooking

android:dependency="cancelBooking"
Kia
  • 124
  • 1
  • 1
  • 10