I\'m beginner in Java Android developing. I\'m using Eclipse SDK 3.6.1 version. I have a preferences window with two checkbox and one back button.
try this:
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, @NonNull Preference preference) {
CheckBoxPreference cb1 = null;
CheckBoxPreference cb2 = null;
ListAdapter adapter = preferenceScreen.getRootAdapter();
for(int i = 0; i < preferenceScreen.getRootAdapter().getCount(); i++)
{
//attention to type and key
Preference pref = (Preference) adapter.getItem(i);
if (pref == null || pref.getKey() == null)
continue;
if (pref.getKey().equals(getString(R.string.tag_preference_key_always_zoom_to_akt_position)))
cb1 = (CheckBoxPreference) pref;
if (pref.getKey().equals(getString(R.string.tag_preference_key_always_zoom_to_last_location)))
cb2 = (CheckBoxPreference) pref;
if (cb1 != null && cb2 != null)
break;
}
//be safe
if (cb1 == null || cb2 == null)
return super.onPreferenceTreeClick(preferenceScreen, preference);
if (preference.getKey().equals(getString(R.string.tag_preference_key_always_zoom_to_akt_position))) {
CheckBoxPreference cb = (CheckBoxPreference) preference;
cb2.setChecked(!cb.isChecked());
}
if (preference.getKey().equals(getString(R.string.tag_preference_key_always_zoom_to_last_location))) {
CheckBoxPreference cb = (CheckBoxPreference) preference;
cb1.setChecked(!cb.isChecked());
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}