Q:

Android - what is the good-practice way of handling button clicks on the header of an app

I am working on a header for an app.  The header will have 4 buttons.  Each button will have a listener and some code to send it to the home of that button.
The Java code for the buttons will be the same so I am wondering what I can do so that I can have that code in one place and reuse it in all my screens. How do people typically handle this kind of a scenario? Should/can I make a utility class and just import that? If I do, then how do I handle code like this so it would know which intent I am on?
          Intent myIntent = new Intent(CurrActivity.this, NextActivity.class);
          CurrActivity.this.startActivity(myIntent);

Thanks!

A:

A couple of options I can think of:-

Have an ActivityBase class or a FragmentBase class that you put all your navigation logic into, all your activities/fragments would subclass from this, therefore share the same nav logic
Create a custom view based of LinearLayout or ViewGroup, treat each child view of this custom view as a navigation item, this might be a bit heavy depending on your experience but definetly the way I would do it these days, info here on custom views http://developer.android.com/guide/topics/ui/custom-components.html

With both options you should look at the include tag that will allow you to share the xml that defines your navigation across layouts.
http://developer.android.com/resources/articles/layout-tricks-reuse.html
Hope that helps.

