Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use with androidannotations.org #4

Open
team55 opened this issue Feb 11, 2014 · 4 comments
Open

how to use with androidannotations.org #4

team55 opened this issue Feb 11, 2014 · 4 comments

Comments

@team55
Copy link

team55 commented Feb 11, 2014

simple code
validation not worked

@EFragment(R.layout.fragment_login)
public class LoginFragment extends Fragment {
    @NotEmpty(messageId = R.string.validation_name)
    @ViewById(R.id.editEmail)
    EditText name;

@NotEmpty(messageId = R.string.validation_password)
    @MinLength(value = 4, messageId = R.string.validation_password_length, order = 2)
    @ViewById(R.id.editPassword)
    EditText password;

@Click(R.id.buttonLogin)
    void LogIn(){

        final boolean isValid = FormValidator.validate(this, new SimpleErrorPopupCallback(getActivity()));

        if (isValid) {

//no problems with no options - although the data is not filled
            SimpleDialogFragment.createBuilder(getActivity(), getActivity().getSupportFragmentManager())
                    .setMessage("All OK")
                    .setPositiveButtonText(android.R.string.ok)
                    .show();
        }

    }
}
@tomas-vondracek
Copy link
Member

That's because AndroidAnnotations generate and use LoginFragmen_ which is inherited from your LoginFragment and FormValidator looks for fields for validation only on direct class, not the parent. Reason for that is performance, but we may include some kind of switch in future. For now, it will unfortunately not work with AndroidAnnotations.

@tomas-vondracek
Copy link
Member

There is a workaround though :)
You can create static inner class holding your views and validate it, the problem is @ViewById probably won't work with that.

@scottzhang
Copy link

I get same problem. After review the source code, because androidannonation is important for me. I find the problem is in file
FieldFinder.java
Replace L57 as
final Field[] fields = target.getClass().getFields();
what replace getDeclareFields with getFields
After fix this, rebuild.

And make sure in your class, mark your EditText as public.
@ViewById
@notempty(messageId = R.string.validation_name, order = 1)
public EditText username;

then everything works fine.

@kemsky
Copy link

kemsky commented Jun 1, 2015

Due to many inner classes with private access it is impossible to create easy patch without rebuilding the whole library and that is really sad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants