我已经在活动中成功使用了 Saripaar,但是现在,当我将它与 一起使用时,即使输入错误DialogFragment
,它也总是会跳转。onSuccess
我Fragment
的正在实施ValidationListener
并且也Validator
被初始化onCreate()
。Fragment
有没有人知道它在片段中的行为..???
这是我的代码概览...
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 事件每次都完美调用......不知道实际上是什么问题,或者我做错了什么......
我怀疑的一件事是,调用getActivity()
in linevalidator = new Validator(getActivity());
可能会导致问题,例如您的实现取决于活动的上下文,并且在对话片段中,我们脱离了上下文……嗯,您可以更好地猜测它……: )