Reputation: 4486
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
Upvotes: 0
Views: 92
Reputation: 5709
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
Upvotes: 0
Reputation: 12207
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
Upvotes: 2