views:

30

answers:

2

I am working on an Android project where a group of buttons needs to show on the bottom of every screen (activity) in the application. The group of buttons are basically a navigation bar. I want to know the best way to do this without creating new buttons for every activity. I have been around programming (C++/C#) for many years but am pretty new to Android and Java so if someone can point me in a general direction, it would be appreciated.

Thanks.

A: 

I bet you need to use "include" tag for xml layouts. It's the best when you need to reuse some UI components. See http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/ for the examples and description.

Konstantin Burov
I think this is exactly what I am looking for. Thank you.
Cameron Ediger
A: 

To elaborate on Konstantin's answer, after you've used include, you'll need to bind actions to these buttons. If the buttons should have the same action regardless of the activity they are in, use the include tag to create their layout and then create a parent NavigationActivity (or whatever else you want to call it) class from which all your other activites will inherits. In the parent NavigationActivity class' onCreate method, you can set up the onClickListener (and other needed stuff) for the buttons.

Julien
Thank you for the clarification, Julien.
Cameron Ediger
I have posted a follow up question here: http://stackoverflow.com/questions/3498673/onclicklistener-not-firing-from-parent-class
Cameron Ediger