0

I am trying to you use Android Annotations (https://github.com/excilys/androidannotations) in an existing project. I cannot convert the whole project to use Annotations. Can I have some activities that utilize annotations and some acitivites that doesn't use Annotations.

But When I did that, some functionalities stopped working. Like If I used only -

@ViewById(R.id.find)
public Button FIND;
...
...
@Override
protected void onCreate(Bundle savedInstanceState) {
   ...
   if (FIND != null) {
        FIND.setOnClickListener(this);
    }
   ...
}

OnClick on the button doesn't work. Is it mandatory to use @Click annotation.

Can't I just use annotations only where I wish to have. And other parts of the code be the old code without annotations. Please guide me.

Thanks

2 Answers 2

2

Please read the doc more carefully. The injected views are first available in the @AfterViews annotated methods:

@AfterViews
void afterViews() {
  // you can use injected views here
} 

https://github.com/excilys/androidannotations/wiki/Injecting-Views#afterviews

Sign up to request clarification or add additional context in comments.

Comments

0

First of all please respect coding convention, you can find ax explanation here

Then, for your question, you can use code of both types: native android and android annotations one. If you inflate a view using @ViewById annotation, you must keep in mind that the injection of the view is done at a certain point of the execution, so before of that your variable will be null. As WonderCsabo reccommended to you, use injected views inside of @AfterViews annotated method.

Otherwise, if you want to mantain android native syntax, you MUST instantiate your view manually with findViewById method. Obviously after that you have setted activity's layout

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.