ouzhiyin / androidannotations

Automatically exported from code.google.com/p/androidannotations
0 stars 0 forks source link

Allow Annotations for Views only #63

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Often you use Custom View classes, especially for things like TabView, 
ViewFlipper contents or custom dialog. You inflate this classes in the View 
subclass and also some logic like button press handlers an so on are in there. 
It would be nice if you can use the annotaions there too. It seems like it is 
not possible the enhance a View class. 
There you don't have a onCreate method, you use the onFinishInflate method to 
inflate your own layout file:
e.g.
mStatsView = inflate(getContext(), R.layout.call_stats, this);
mStatList = (ListView) mStatsView.findViewById(R.id.CallStatisticList);

If you don't do that you will get a really huge Activity class. 

Original issue reported on code.google.com by mail.mic...@gmail.com on 17 Apr 2011 at 11:23

GoogleCodeExporter commented 9 years ago
Thank you for your suggestion!

I think we might be able to do something about thing, for instance by creating 
a subclass of the custom view, inflating the layout and injecting the views.

Do you have a working example, or maybe a sample from some code repository, so 
that we may have a global view on what's needed ?

Original comment by py.ricau on 17 Apr 2011 at 1:50

GoogleCodeExporter commented 9 years ago
A class of an application of mine: http://pastebin.com/a3QHu77C

Original comment by mail.mic...@gmail.com on 17 Apr 2011 at 1:59

GoogleCodeExporter commented 9 years ago
Thanks!

I think we could create a @ELayout annotation for classes that extend 
ViewGroup. This annotation could take a layout id parameter.

We could then enable usage of @ViewById as well as events (e.g. @Click, @Touch, 
etc). I don't know if usage of @Extra, @StringRes, @Background / @UiThread, and 
@Services is actually a good idea or not (mixing view code with this kind of 
code might not be a "good practice").

Please let me know what you think about this.

Original comment by py.ricau on 17 Apr 2011 at 3:00

GoogleCodeExporter commented 9 years ago

Original comment by py.ricau on 17 Apr 2011 at 3:01

GoogleCodeExporter commented 9 years ago

Original comment by py.ricau on 17 Apr 2011 at 3:01

GoogleCodeExporter commented 9 years ago
Yes sounds good. And you are right more logic at this place is maybe not a good 
practice. But pushing it to activity is also not nice as i think. HArd to make 
a good choice. Android itself does not force someone to have a good modularized 
code. It tends to have enormous Activity classes. 

Original comment by mail.mic...@gmail.com on 17 Apr 2011 at 3:05

GoogleCodeExporter commented 9 years ago
I had totally forgotten about this issue. @jzapata started working on a similar 
idea in issue 113, and he'll integrate your ideas as well.

Original comment by py.ricau on 19 Oct 2011 at 9:43

GoogleCodeExporter commented 9 years ago

Original comment by py.ricau on 20 Oct 2011 at 7:35