Issue
I have a need 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 behaviour: every button maps to an activity.
I have two solutions for this:
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.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.
I am not sure which approach to follow. Please advice. Alternatives also appreciated
Following is what I think about above approaches:
The problem with the first approach:
It will generate a lot of boilerplate code(findViewByIds, setOnClickListener etc.)
Assuming that there are 5 activities and 3 tab buttons, the total number of Button objects created at Runtime will be 5 x 3 = 15
I'd like to take the 2nd approach because:
All the code(state and behaviour) will be encapsulated by the widget class. Less Boilerplate code.
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.
Thanks.
Solution
Unfortunately, I couldn't find a way to customize the built-in TabWidget to make it look like UITabBar. So, I am going to create a custom control and have the Buttons as static members(take the second approach). The control will handle the clicks as expected.
I've notice that the award winning Plink Art application too has a tab control that is similar to iPhones UITabBar.
Answered By - Samuh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.