Reputation: 2564
I have two ListFragments which needs to share some code. This was very basic by just creating a abstract fragment extending ListFragment and then let my two fragments both extend my abstract fragment.
However, now I need a third fragment to use the code from my abstract fragment. However, this third fragment is not a ListFragment but a GridFragment.
Is there a good way to solve this problem?
Upvotes: 5
Views: 716
Reputation: 121998
As java won't support multiple inheritance
either seperate your generic code in to Fragment
Super class or make static methods.
or
Simply write a FragmentUtil
class.
Upvotes: 2
Reputation: 505
I would suggest you put your shared code in class that dont extends any Fragments. In your fragments classes you make calls to your SharedCode.class .
Upvotes: 1