简体   繁体   中英

how to use single fragment for ViewPager Swipe Tabs in Java Android

I created three fragments for three swipe Tabs,but How to use single fragment for all three Tabs in Java Android.Please any one give me answer or share if you have any tutorial.

Thanks...

In your FragmentPagerAdapter edit getItem methods to be like this

@Override
    public Fragment getItem(int position) {

        return YourFragment.newInstance(id);
    }

In you Fragment Class add something like this

public class YourFragment Fragment{

    public static YourFragment newInstance(String id) {
        Bundle args = new Bundle();
        args.putInt(ARG_PAGE, id);
        YourFragment fragment = new YourFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    }
}

Check this full tutorial also: https://guides.codepath.com/android/ViewPager-with-FragmentPagerAdapter

I hope this helps you, any question you are welcome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM