如何setOnClickListener(),以一个EditText preference对话框的确定​​按钮? [英] How to setOnClickListener() to OK button of an EditTextPreference Dialog?

查看:925
本文介绍了如何setOnClickListener(),以一个EditText preference对话框的确定​​按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/7527894/how-to-call-the-ok-button-in-the-edittext$p$pference\">how打电话的OK键的EditText preference

我想验证输入(输入6位数字)一个EditText preference对话框。

I want to validate the Inputs (enter 6 digits) of an EditTextPreference dialog box.

这是我的(相关)preferences.xml片段的样子:

This is how my (relevant) preferences.xml snippet looks like :

            <!--EditTextPreference-->
            <com.app.preferences.UpdatePincodePreference
                android:key="PIN_CODE_PREFERENCE"
                android:title="@string/pincode_preference_title" 
                android:summary="@string/pincode_preference_summary"
                android:dialogTitle="@string/pincode_preference_dialog_title"
                android:dialogMessage="@string/pincode_preference_dialog_message" 
                android:inputType="number"
            />

我如何测试在preference对话框的EditText的用户没有输入小于或超过6位数?

How do I test that the user has not entered less or more than 6 digits in the EditText of the preference dialog?

基本上我需要确定按钮设置onClickListener(),但如何我得到的OK按钮,我没有定义的保持。它的一个EditText preference的默认视图,所以是取消按钮。

Basically I need to set an onClickListener() on the OK button, but how to I get a hold of the OK button which I did not define. Its the default view of an EditTextPreference, and so is the Cancel button.

的问题是完全一样的<一href=\"http://stackoverflow.com/questions/7527894/how-to-call-the-ok-button-in-the-edittext$p$pference\">how以呼叫的EditText preference OK按钮,但接受的解决方案中提供的链接现在被破坏。

The question is exactly the same as "how to call the ok button in the EditTextPreference" but the links provided in the accepted solution are broken now.

推荐答案

这可以使用来实现挂线preferenceChangeListener()

This could be achieved using setOnPreferenceChangeListener()

public UpdatePasswordPreference(Context context, AttributeSet attrs) {


    this.setOnPreferenceChangeListener(new OnPreferenceChangeListener() 
    {   
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) 
        {
            MobicopLogger.d("Preference input changed");
            try 
            {
                if(newValue.toString().length() != 6)
                    return false;
                else
                    return true;
            }
            catch(Exception e)
            {
                return false;
            }
        }

    });


}

这篇关于如何setOnClickListener(),以一个EditText preference对话框的确定​​按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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