Search code examples
androidextends

How do I extend two classes


I have this android application and I am trying to extend two classes at the same time. I have this code:

public class TimelineFragment extends Fragment {
    public class TimelineFragment extends Activity {
        //all codes here
    }
}

On my second TimelineFragment, it has an error that says: The nested type TimelineFragment cannot hide an enclosing type


Solution

  • I have this android application and I am trying to extend two classes at the same time

    That is not possible. Java does not support multiple inheritance.

    I have this code

    Given your class name is TimelineFragment, one presumes that it should extend Fragment. Whatever problem you are trying to solve via multiple inheritance will need to be solved in some other way. For example, if you are trying to perform operations on the activity that hosts your fragment, you can call getActivity() from the fragment.