0

I'm using a view pager library in my application, where I use switch case with view pager. Here my code:

private class MyPagerAdapter extends FragmentPagerAdapter {

    public MyPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int pos) {
        switch (pos) {

        case 0:
            return Slider_One_Fragment.newInstance();

        case 1:
            return Slider_Two_Fragment
                    .newInstance("Slider_Two_Fragment, Instance 1");
        case 2:
            return Slider_Three_Fragment
                    .newInstance("Slider_Three_Fragment, Instance 1");
        default:
            return new MainActivity();
        }
    }

    @Override
    public int getCount() {
        return 3;
    }
}

here the return type is of type "Fragment". But in default case I need to have a activity "MainActivity". Can anybody please help me to solving this issue?

Anjali Tripathi
  • 1,477
  • 9
  • 28
Parthiban M
  • 1,104
  • 1
  • 10
  • 30

1 Answers1

-1

the way the the ViewPager is setup it has to be a Fragment and not An Activity. One suggestion that you could do is move all the logic out of the MainActivity and into a MainFragment. then have your MainActivity contain the MainFragment.

leibreichb1
  • 457
  • 2
  • 7