Tabs and Swipe - editing the getItem to display 3 different fragments

后端 未结 1 2023
野的像风
野的像风 2021-01-03 08:16

I have been at this for about 3 days looking up various websites for reference, but I am stuck. I am using the swipe and tabs layout which give you the standard dummy sectio

相关标签:
1条回答
  • 2021-01-03 08:58

    Use the method this way:

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a DummySectionFragment (defined as a static inner class
            // below) with the page number as its lone argument.
        switch (position) {
            case 0:
                Fragment fragment = new DummySectionFragment();
                Bundle args = new Bundle();
                args.putInt(fragment.ARG_SECTION_NUMBER, position + 1);
                fragment.setArguments(args);
                return fragment;
    
              case 1:
                Fragment fragment2 = new DummySectionFragment2();
                Bundle args = new Bundle();
                args.putInt(fragment2 .ARG_SECTION_NUMBER, position + 2);
                fragment2.setArguments(args);
                return fragment2;
    
              case 2:
    
                 Fragment fragment3 = new DummySectionFragment3();
                 Bundle args = new Bundle();
                 args.putInt(fragment3.ARG_SECTION_NUMBER, position + 3);
                 fragment3.setArguments(args);
                 return fragment3;
    
    
            default:
                return null;
            }
    
    
        }
    
    0 讨论(0)
提交回复
热议问题