onUserInteraction不工作的对话框preference [英] onUserInteraction not working in DialogPreference

查看:239
本文介绍了onUserInteraction不工作的对话框preference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据预计, 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 Dialogs window callback by issuing:

dialog.getWindow().setCallback(callbackImplementation);

注意:这个实现应该通过调用适当的对话方式处理所有接收到的事件或处理以自己的方式的事件(手动调用 onUserInteraction())。

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.

  1. 呼叫对话preference.get preferenceManager()方法,它返回 preferenceManager 。它有一个 getActivity()方法但它的包私人所以你必须把你的自定义对话preference 机器人。preference 包来访问它。

  1. Call DialogPreference.getPreferenceManager() method which returns PreferenceManager. It has a getActivity() method but it's package-private so you would have to put your custom DialogPreference in android.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆