如何调用中的EditText preference ok键 [英] how to call the ok button in the EditTextPreference

查看:830
本文介绍了如何调用中的EditText preference ok键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的EditText preference preferenceActivity 。当用户点击的EditText preference 将显示一个对话框。在对话框中,用户可以输入一个值,该对话框中有确定和取消按钮。我想打电话的确定按钮的单击事件来检查值,但我不知道该怎么称呼点击均匀。

I have an EditTextPreference in the PreferenceActivity. When user click the EditTextPreference will show a dialog. In the dialog, user can input a value, and the dialog has "OK" and "Cancel" buttons. I want to call the click event of ok button to check the value, but I do not know how to call the click even.

我知道我可以使用的EditText preference.setOn preferenceChangeListener(),但我想知道我是否可以使用OK按钮点击事件。

I know I can use EditTextPreference.setOnPreferenceChangeListener(), but I want to know if I can use OK button click event.

推荐答案

其实,你不能因为preference是一个内部 AlertDialog.Builder 并创建一个新的对话框每次点击preference。接下来的问题是,对话框生成器设置点击监听你,如果你忽略他们,你可能会破坏的按钮,点击关闭行为。

Actually you can't since the preference is using an internal AlertDialog.Builder and creates a new dialog every time you click the preference. The next problem is that the dialog builder sets the click listener for you and if you override them you might destroy the close behavior of the button click.

这困扰着我,因为我想一个preference只逢有效输入(否则举杯显示和用户应该preSS取消,如果他无法得到它的权利)。

This bothered me since I wanted a preference which only closes on valid input (otherwise a toast is shown and user should press cancel if he can't get it right).

(如果你确实需要的正是这个问题的解决方案),你可以找到一个验证对话preference <一个通用的解决方案href="https://github.com/Knickedi/android-toolbox/blob/master/android_toolbox/src/de/viktorreiser/toolbox/$p$pference/ValidatedDialog$p$pference.java"相对=nofollow>这里和验证的EditText preference <一个href="https://github.com/Knickedi/android-toolbox/blob/master/android_toolbox/src/de/viktorreiser/toolbox/$p$pference/ValidatedEditText$p$pference.java"相对=nofollow>此处我写我自己。

(If you really need a solution for exactly this problem) You can find general solution of a validating DialogPreference here and a validating EditTextPreference here which I wrote myself.

这篇关于如何调用中的EditText preference ok键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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