Android的Saripaar问题与片段(DialogFragment) [英] Android Saripaar issue with fragments (DialogFragment)

查看:495
本文介绍了Android的Saripaar问题与片段(DialogFragment)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Saripaar之内成功的活动,但现在,当我使用它与 DialogFragment ,它总是转到的onSuccess 即使是在错误的输入,以及。

I have used Saripaar successfully within activities, but now, when I use it with DialogFragment, it always go to onSuccess even in wrong input as well.

我的片段正在实施 ValidationListener 验证是在的onCreate初始化() 片段以及

My Fragment is implementing ValidationListener and Validator is initialized in onCreate() of Fragment as well.

有没有人有关于它的碎片行为想法.. ???

Does anyone has idea about its behaviour in fragments..???

下面是我的code在查看...

Here is my code over view...

public class MyDialogFragment extends DialogFragment implements ValidationListener {
    // Declaring validator
    private Validator validator;

    // views to validate
    @Required(order = 1)
    @TextRule(order = 5, minLength = 6, message = "Enter at least 6 characters.")
    private EditText nameEditText;

    @Required(order = 2)
    private EditText addressEditText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Initializing validation process
        validator = new Validator(getActivity()); /*====*/
        validator.setValidationListener(this);
    }

    positiveButton.setOnClickListener(new View.OnClickListener() {
        @Override
            public void onClick(View v) {
            // Validating on positive button event
                validator.validate();
            }
        });
    }

    // Here are the validation listener methods to implemented
    // Just copy pasted from you github account tutorial page
}

每一件事情似乎是正确的......的onSuccess事件被调用每次完美......不知道什么是真正的问题,或即时通讯做错了什么......

Every thing seems right...onSuccess event is invoking perfectly everytime...Don't know what is the issue actually, or where im doing something wrong...

有一件事我怀疑是,符合来电 getActivity()验证=新的验证器(getActivity()); 可能导致的问题,比如你的实现是根据活动的背景下,并在对话片段,我们是断章取义的一些事情......好吧,你能猜到它更好的... ...:)

One thing i suspect is, call to getActivity() in line validator = new Validator(getActivity()); might cause issue, like your implementation is depending on context of activity, and in dialog fragment, we are out of context some what...well, you can guess it better...:)

推荐答案

试试这个,

validator = new Validator(this); /*====*/

而不是

validator = new Validator(getActivity()); /*====*/

另外,请使用最新的源代码。罐子有点过时。让我知道,如果这有助于。

Also, please use the latest source. The jar is a bit outdated. Let me know if this helps.

这篇关于Android的Saripaar问题与片段(DialogFragment)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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