Search code examples
javaandroidimageviewglsurfaceview

Android Java App: Extending two classes (walk around)


I have two classes, ImageMap, extending ImageView and PageView extending GLSurfaceView, I am using the ImageMap to mainly have hot spots on drawables but I also need to add a page flip/curl animation to it, in order to do that I need those two classes to act as one object, any idea how to do that?

It is totally clear to me that multiple inheritance is not allowed in java.


Solution

  • There is no way of really extend two classes. What you can do is:

    1. You make a wrapper object, that holds one instance of each object. and simply do this.ImageMap.filed1 and so. This is more convenient while developing the class. This also allows you to proxy method invocations.
    2. You define interfaces which should be implemented, and you make a new class which implements both. This is only for class that use this class to have the interface, without really caring about the implementation.

    You may need both things, since the first is about "how to do it" and the second about "how it will be presented to objects that use it".