本文介绍了如何setOnTouchListener()在列表preference?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在视图处理的onTouchEvent很简单,因为每个视图具有setOnTouchListener()方法来做到这一点。Handling onTouchEvent on a view is straightforward as every view has the setOnTouchListener() method to do just that.唉,虽然目录preference 是一个视图,它不是在布局中的XML定义的,并且因此无法通过findViewById()访问。所以......我似乎没有弄清楚如何setOnTouchListener()吧。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.我的想法是让对它的引用在preferenceActivity的onCreate(),然后getDialog()的 getCurrentFocus(),但在那个时间特定的时刻,没有焦点,甚至没有一个对话框(getDialog()返回null,确认)。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?推荐答案使用 registerOnShared preferenceChangeListener(OnShared preferenceChangeListener监听器)的共享preferences,如果你有兴趣在所有的preferences,或 .setOn preferenceChangeListener(听众)如果你只是想知道在一个项目的变化。您将会收到通知时,preference改变。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. 这篇关于如何setOnTouchListener()在列表preference?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-18 02:35