madcoderz
madcoderz

Reputation: 4431

extend 2 classes problem android

i'm a junior programmer. I have a base class that extends activity, i use this class to set up the menu in my app. All my activity classes extends this base class. Now, i have a new class which extend ExpandableListActivity this class's purpose is to show an expandable list and of course when the user is viewing this activity the menu becomes unavailable. So how can i do to be able to use the menu while viewing the expandable list. I know that it's impossible to extend more than one class in Java, so what's the trick?

Thanks in advance

Upvotes: 0

Views: 2243

Answers (2)

AlexKorovyansky
AlexKorovyansky

Reputation: 4943

You can use delegation. Extract all methods related to Menu in separate MenuDelegate class.

Your new class will extend ExpandableListActivity, and delegate all methods related with Menu to MenuDelegate. It's useful solution if your Menu logic is simple.
In this case, your other activities will be free, and will be able to extend ListActivity, TabActivity or something else..

http://en.wikipedia.org/wiki/Delegation_pattern

Upvotes: 2

Robby Pond
Robby Pond

Reputation: 73484

You don't have to extend ExpandableListActivity to have an ExpandableList in your layout. You can extend your BaseActivity and handle the ExpandableList on your own. The ExpandableListActivity is just a helper class.

Upvotes: 1

Related Questions