umar umar - 5 months ago 31
Android Question

Extending from two classes

How can I do this:

public class Main extends ListActivity , ControlMenu

Also, I would like to know that is this approach is okay that I have made the menus in class which is ControlMenu and I am extending in rest of the activities.


You can only Extend a single class. And implement Interfaces from many sources.

Extending multiple classes is not available. The only solution I can think of is not inheriting either class but instead having an internal variable of each class and doing more of a proxy by redirecting the requests to your object to the object that you want them to go to.

 public class CustomActivity extends Activity {

     private AnotherClass mClass;

     protected void onCreate(Bundle savedInstanceState) {
         mClass = new AnotherClass(this);

     //Implement each method you want to use.
     public String getInfoFromOtherClass()
        return mClass.getInfoFromOtherClass();

this is the best solution I have come up with. You can get the functionality from both classes and Still only actually be of one class type.

The drawback is that you cannot fit into the Mold of the Internal class using a cast.