I have a requirement to create a control similar to UITabBar in
iPhone, which is to be present on every activity of my application.
UITabBar essentially is a battery of buttons exhibiting a TAB like
behavior: every button maps to an activity.
I have two solutions for this:
1. In the layout XML for every activity, I insert a
<LinearLayout><Button/><Button/><Button/></LinearLayout> element. And
then have a common listener class that will handle the button clicks.
So, every activity will have an instance of this listener.
2. To create a custom Widget extending LinearLayout class, put all the
buttons as its static members and let it handle the button clicks.
Include this custom control in every screen.

Following is what I think about this:
The problem with first approach:
1. it will generate a lot of boiler plate code(findViewByIds,
setOnClickListener etc.)
2. Assuming that there are 5 activities and 3 tab buttons, total
number of Button objects created at Runtime will be 5 x 3 = 15

I'd like to take the 2nd approach because:
1. All the code(state and behavior) will be encapsulated by the widget
class. Less Boilerplate code.
2. Since, the buttons will be static members, the total number of
Button objects created at Runtime will be only three. Though, the
static members will remain in memory for a longer time(until JVM
unloads the class), since the control is present on every screen I
think this can be excused.

I am not sure which approach to follow. Please advice. Alternatives
also appreciated.

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to