onUserInteraction不工作的对话框preference [英] onUserInteraction not working in DialogPreference
问题描述
据预计, onUserInteraction
正在呼吁任何用户交互。它工作正常,在 preferenceActivity
。然而,当对话preference
是弹出, onUserInteraction
不叫了,甚至有用户交互,如触摸事件。
It is expected that onUserInteraction
is being called for any user interaction. it works fine in PreferenceActivity
. However, when a DialogPreference
is popup, onUserInteraction
is not called anymore even there is user interaction such as touch event.
看来,对话框preference
并不是唯一的案例。每当对话框
显示,它不报告的用户交互的活动。
It seems that DialogPreference
is not the only case. Whenever Dialog
is shown, it does not report the user interaction to activity.
不过,我能做些什么,如果我真的需要它。谢谢你。
But what can I do if I really need it. Thank You.
推荐答案
据我所知, onUserInteraction()
当用户与互动根本就没有所谓的一个对话框。
As far as I know, the onUserInteraction()
is simply not called while the user is interacting with a dialog (even started from Activity
in which you're monitoring interactions).
两种解决方案,我知道有:
Two solutions I know are:
-
子类
对话框
/对话preference
类并覆盖dispatchTouchEvent ()
。
实施 Window.Callback
接口,并将其设置为对话框
的窗户回调发出命令:
Implement Window.Callback
interface and set it as Dialog
s window callback by issuing:
dialog.getWindow().setCallback(callbackImplementation);
注意:这个实现应该通过调用适当的对话方式处理所有接收到的事件或处理以自己的方式的事件(手动调用 onUserInteraction()$ C例如$ C>)。
Note: this implementation should process all received events by calling appropriate dialog methods or handle the events in your own way (e.g. by manually calling onUserInteraction()
).
修改
您有几个方法来获得活动
在自定义的 preferenceDialog
实例。
You have couple of ways to get Activity
from the custom PreferenceDialog
instance.
-
呼叫
对话preference.get preferenceManager()
方法,它返回preferenceManager
。它有一个getActivity()
方法但它的包私人所以你必须把你的自定义对话preference
在机器人。preference
包来访问它。
Call
DialogPreference.getPreferenceManager()
method which returnsPreferenceManager
. It has agetActivity()
method but it's package-private so you would have to put your customDialogPreference
inandroid.preference
package to access it.
在 preferenceActivity.onCreate()
,充气preferences后,使用找到preference ()
来寻找您的自定义对话preference
按键。然后,它通过访问转换为自定义类和一套活动这
。
In the PreferenceActivity.onCreate()
, after inflating the preferences, use findPreference()
to find your custom DialogPreference
by key. Then cast it to your custom class and set activity to this
via an accessor.
我会去的第二个选项。
这篇关于onUserInteraction不工作的对话框preference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!