开发者

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 开发者_JAVA百科that it's impossible to extend more than one class in Java, so what's the trick?

Thanks in advance


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜