如何检查一个EditText preference值的用户验证之前? [英] How can I check an EditTextPreference value before the User validate it?

查看:369
本文介绍了如何检查一个EditText preference值的用户验证之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前是preference在我的应用程序,用户会被提示2和10数值之间进入。

I have currently a Preference in my application where the user is prompted to enter between 2 and 10 numerical values.

由于此功能仅适用于高级用户和beta测试,不公开发行,我决定让他们进入一个CSV值。

As this feature is only available for power users and beta testers, not for public release, I decided to let them enter a CSV value.

所以,在我的EditText preference,一些用户会输入:1; 20; 30,其他一些会进入1; 10; 10; 10; 10; 10; 10; 10等。

So, in my EditTextPreference, some users will enter: "1;20;30", some other will enter "1;10;10;10;10;10;10;10" etc...

后,在我的code,我只是拆分这些值来构建一个数组,并执行我的code。
我不得不承认,这不是很专业,但是这只是工作!

After, in my code, I am just splitting these values to build an array and execute my code. I have to admit that's not very professional, but that just works!

String[] patternString = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getString("vibPattern", "0;500;500;500;500;500;500;500").split(";");

主要的问题是,我想检查字符串的有效性,而用户正在写呢!

The main issue is that I would like to check the validity of the String while the user is writing it!

一些你是否有一个想法如何做到这一点?

Does some of you have an idea how to achieve that?

推荐答案

您需要使用<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener%28android.text.TextWatcher%29\"相对=nofollow> addTextChangedListener 等行为,按照该是,好了,改变...

you need to use "addTextChangedListener" and act according to the text that was , well, changed...

如果你愿意,你可以使用普通的前pressions以检查有效性。

if you wish, you can use regular expressions in order to check for validity .

这篇关于如何检查一个EditText preference值的用户验证之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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