I'm trying to implement OnPreferenceClickListener
over PrefernceFragment
and it seems like the onPreferenceClick()
is never called.
I have another PrefernceFragment
implementing OnSharedPreferenceChangeListener
and it works just fine.
Is this a bug of the OS ? is the OnPreferenceClickListener
not supposed to be supported for PrefernceFragment
?
If there is no need to register the fragment as listener as I read, then I really think my code is correct.
public class myClass extends PreferenceFragment implements OnPreferenceClickListener {
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(com.XX.ZZ.R.xml.YY);
}
@Override
public boolean onPreferenceClick(Preference preference) {
// never called.
}
}
PreferenceFragment
doesn't have aonPreferenceClick()
method. There is really no need to listen for click events since the Android fragment takes care of writing the preference values into memory. If you really need to watch for a click event, you can usefindPreference(CharSequence key)
to find each of thePreference
s you want to watch and then callsetOnPreferenceClickListener(this)
on those.