Answer the question
In order to leave comments, you need to log in
How to correctly implement "control" for multiple use?
Let's say you need to develop a kind of "reader" that can be used in other projects.
"Reader" is a collection of logic (the code that is currently placed in the Activity), graphic files (different icons for choosing the font size, etc.), resource files (dimens, colors, strings), xml markup (layouts , drawable, selectors, custom views).
Interaction with the “outside world” (with the project that uses it) was supposed to be passed to this Activity as an object of a known type (or an object that implements a known interface), from which you can ask everything else.
It is desirable that you do not need to copy-paste the whole thing into each project and that by changing the code, it will change in other projects that use it (that is, so that the projects seem to refer to the developed "control"). The Reader uses ActionBarSherlock (and possibly a couple of other libraries).
Implement as a library? Make it a fragment? Any advice, even Captain Obvious style, would be helpful.
Answer the question
In order to leave comments, you need to log in
In the form of a fragment, you can make it only for ease of use (for those who use fragments).
It is necessary that the control can be embedded without a fragment (which means that there should not be any logic in the fragment).
I suppose that one of the most correct options would be to inherit from View (or ViewGroup for a set of controls), i.e. writing your view. Further, I would send events to the controller (independent of the GUI) on the actions of the view, which would do the necessary actions and send events (response) back to the view.
Thank you!
I kind of understood about creating my own View and controller. Then this View is placed in the fragment, and the fragment in the Activity.
And the project that will use the operating time will be inherited from this activity or launch it directly, right? Or we stop at View (or fragment) and use it in our Activity. I still don't understand how it will be and how it will be more convenient.
About customization correctly noticed, it is needed. Show/hide some buttons, change the background. As far as I understand, additional attributes are created for the View, and this is exactly what we are talking about , right?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question