views:

134

answers:

2

Hi,

In one of my Android Application I need to keep the title bar same but the view that is shown in the rest of the screen changes. So, I have taken different Activity for all the views that I need to show and set the title bar in every Activities onCreate method.

Now, the problem is that I have a button in the title bar and need to perform certain action on its click event. Writing the same event handling code in every Activity class is very cumbersome. Is there any other way out that whenever there is a click event on that button of the title bar then we can have the same functionality without writing the same code in all the Activity classes.

Can we use ViewGroup for that? I don't have much idea about ViewGroup. Is that possible with ViewGroup?

If anyone knows the solution then please let me know.

Thanks & Regards Sunil

+1  A: 

If you are sharing view elements and functionality amongst several classes extending Activity, you might want to consider making a common superclass to handle this overlap.

jqpubliq
A: 

Hi,

I have been able to extend the class and get the button click event in the same Activity.

But now there is another issue. I want to display images in Gallery from that button click but its not happening so if I click on that button from another activity. The onclick method is being called but its not changing the view to Gallery. If I click on that button from the main Activity in which there is the button logic then the Gallery view is being displayed.

Can anyone let me know what is the problem?

Thanks & regards Sunil

sunil