我在设置页面中有一个列表偏好设置,当选择列表中的某个值时,我想执行一个操作。但是,当选择项目时,onClick监听器没有被调用。它只有在列表名称被点击时才会被调用。下面是相关代码:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class AAFlows extends PreferenceFragment implements Preference.OnPreferenceClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_flows);
setHasOptionsMenu(true);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
ListPreference flows = (ListPreference) findPreference(getString(R.string.pref_key_flows));
flows.setOnPreferenceClickListener(this);
}
@Override
public boolean onPreferenceClick(Preference preference) {
ListPreference flows1 = (ListPreference) findPreference(getString(R.string.pref_key_flows));
Log.d("TestingOutside2",flows1.getValue());
return true;
}
}
当列表中的任何一个值被选择时,我该如何触发一个操作?
下面是列表的图片:
![enter image description here](https://istack.dev59.com/rU6QY.webp)