0

I was having some problem when trying extend more than one class in Android development. So basically what I am trying to do is I got a navigation drawer:

customAdapter = new CustomExpandAdapter(this, listParent, listDataChild);
mDrawerList.setAdapter(customAdapter);
mDrawerList.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE);

    // Navigation drawer with sub menu goes here
private void selectItem(int groupPosition, int position) {
    selectedPosition = position;
    mDrawerLayout.closeDrawer(navDrawerView);

    // Navigation item for profile
    if (groupPosition == 0) {
        switch (selectedPosition) {
        case 0:
            break;
        case 1:
            break;      
    else if (groupPosition == 3) {
        switch (selectedPosition) {
        case 0:
            break;
        case 1:
            Toast.makeText(ENeighbourhoodActivity.this, "Analyze Event",
                    Toast.LENGTH_LONG).show();
            break;
        }
    }
    setTitle(mEventSelection[selectedPosition]);
}

And these codes are in my MainActivity.java. Then from my MainActivity, when I selected certain button, I will navigate to Detail.java. However, in my Detail.java, I am extending FragmentActivity because I am using tab inside Detail.java:

public class EventDetailMain extends FragmentActivity {
Context context = this;

ViewPager Tab;
EventDtlTabPagerAdapter TabAdapter;
ActionBar actionBar;
}

And when I go to Detail.java, the navigation drawer is no longer there because I did not extend from the class. I wonder how should I extend from two class at the same time.

Thanks in advance.

QWERTY
  • 2,303
  • 9
  • 44
  • 85
  • You can't extend from more than one class; you can, however, implement more than one interface. Java supports multiple inheritance of _behaviour_, not state. – fge Dec 14 '14 at 14:04
  • So I should make my navigation drawer class as interface so that my Detail.java could extends from fragmentActivity and implements the interface? – QWERTY Dec 14 '14 at 14:14
  • @fge Can I assume that? – QWERTY Dec 14 '14 at 14:30
  • That is a possibility indeed, yes – fge Dec 14 '14 at 14:45
  • @Denise just a hint: inheritance is evil. The less you use it the better and simpler your code. – eleven Dec 14 '14 at 15:00
  • @Foxinsocks inheritance _done badly_ is evil; but that's the same with everything – fge Dec 14 '14 at 15:43
  • @Foxinsocks Other than using inheritance, do you have any other ideas how to perform it? – QWERTY Dec 15 '14 at 00:28

1 Answers1

0

In main activity take Detail.java as a fragment and write your code.In this way the navigation drawer available to the your Detail.java also.

amar
  • 137
  • 2
  • 12