Fragmentactivity in tab Swiper

Asked

Viewed 53 times

0

I’m not getting to insert a Fragmentactivity for tab Swiper:

@Override
    public Fragment getItem(int position) {
        switch (position) {case 0:
            return new HomeActivity();
        case 1:
            return new ListaBancada();

        }
        return null;

    }

class is Homeactivity inherits from Fragment, the Listed Fragmentactivity and the List Bench gives error in the code above, why? How to call a Activity there?

  • 2

    You can’t call it. The method getItem() returns a Fragment, which is different from FragmentActivity, that despite being an Activity that supports contain Fragments, it is still an Activity and not a Fragment. Fragments are one thing, activities are another.

  • And I can call this Activity inside the Fragment. the whole fact is that I have an Activity ready and I want to put in place this Fragment

  • 1

    An Activity can contain Fragments, not the other way around. You will have to convert your Activity into a Fragment and use it on the switch.

  • Okay Piovezan! I’m going to have to dig into this a lot more thank you once again.

  • No problem. I posted an answer to your question for you to accept.

1 answer

2


You can’t call it. The method getItem() returns a Fragment, which is different from FragmentActivity, that despite being a Activity own to contain Fragments, still is a Activity and not a Fragment. Fragments are a thing, activities are another.

One Activity may contain Fragments, not the other way around. You will have to convert your Activity in a Fragment and use it on switch.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.