How to setOnTouchListener() on a ListPreference?

孤人 提交于 2019-12-01 18:14:11

问题


Handling onTouchEvent on a view is straightforward as every view has the setOnTouchListener() method to do just that.

Alas, although ListPreference is a view, it isn't defined in a layout XML, and thus can't be accessed via findViewById(). So... I don't seem to figure out how to setOnTouchListener() for it.

My idea was to get a reference to it in PreferenceActivity's onCreate(), then getDialog().getCurrentFocus() but at that particular moment in time, it has no focus and not even a dialog (getDialog() returns null, confirmed).

Any idea how to work around this?


回答1:


Use registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) for the shared preferences, if you are interested in all the preferences, or .setOnPreferenceChangeListener(listener) if you only want to know the changes on one item. You will be notified when the preference is changed.



来源:https://stackoverflow.com/questions/17192066/how-to-setontouchlistener-on-a-listpreference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!