public class SomeFragment extends Fragment implements Validator.ValidationListener {
Validator validator;
@NotEmpty(emptyTextResId = R.string.warning_text1_required)
EditText text1;
@NotEmpty(emptyTextResId = R.string.warning_text2_required)
EditText text2;
@Optional
@Min(value = 0, messageResId = R.string.warning_int1_format)
EditText int1;
@Optional
@Min(value = 0, messageResId = R.string.warning_int2_format)
EditText int2;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
validator = new Validator(this);
text1 = (EditText) rootView.findViewById(R.id.product_editor_text1);
....
text1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
validator.validate();
}
}
} );
// same for the remaining views
validator.setValidationListener(this);
}
}
And the log reads:
com.mobsandgeeks.saripaar.exception.ConversionException: Expected an integer, but was
at com.mobsandgeeks.saripaar.adapter.TextViewIntegerAdapter.getData(TextViewIntegerAdapter.java:36)
This would be correct if this wouldn't be for the text1EditText but for one of the ints.
So what am I missing? It seems the validator is using the Adapter that was last registered, which might be the TextViewIntegerAdapter so I tried to explicitly register different ViewDataAdapters for different validators like this:
intValidator = new EditIntValidator(this);
intValidator.registerAdapter(EditText.class, new ViewDataAdapter<EditText, Integer>() {
@Override
public Integer getData(EditText view) throws ConversionException {
return Integer.parseInt(view.getText().toString().trim());
}
});
textValidator = new EditTextValidator(this);
textValidator.registerAdapter(EditText.class, new ViewDataAdapter<EditText, String>() {
@Override
public String getData(EditText view) throws ConversionException {
return view.getText().toString();
}
});
Anyways, this still brought the above ConversionException for my text editor and it still uses the TextViewIntegerAdapter instead of the explicitly registered one.
Here's what I wrote:
And the log reads:
This would be correct if this wouldn't be for the
text1
EditText
but for one of theint
s.So what am I missing? It seems the
validator
is using theAdapter
that was last registered, which might be theTextViewIntegerAdapter
so I tried to explicitly register differentViewDataAdapter
s for different validators like this:Anyways, this still brought the above
ConversionException
for my text editor and it still uses theTextViewIntegerAdapter
instead of the explicitly registered one.Any Ideas?