I'm trying to implement a swipe inside a fragment! My application use a Navigation Drawer Layout and I change view with the drawer. All the view that I show are fragment. Now, I want to implement into a specific fragment an horizontal swipe. How can I do this thing? my code is here :
public class MybookingFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
final View Rootview = inflater.inflate(R.layout.mybooking, parent, false);
ViewPager viewPager = (ViewPager) Rootview.findViewById(R.id.viewpager);
FragmentManager fragmentManager = getChildFragmentManager();
viewPager.setAdapter(new SlidingPagerAdapter(fragmentManager));
return Rootview;
}
my adapter code is here
public class SlidingPagerAdapter extends FragmentStatePagerAdapter {
private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
public SlidingPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
Class fragmentClass = null;
switch (position) {
case 0:
fragmentClass = UpcomingOrder.class;
case 1:
fragmentClass = RunningOrder.class;
break;
case 2:
fragmentClass = CompletedOrder.class;
break;
default:
fragmentClass = UpcomingOrder.class;
break;
}
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return fragment;
}
@Override
public int getCount() {
// For this contrived example, we have a 100-object collection.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
}
Try this below example. I think you are asking this only
You have to use main fragment. with in that fragment you have to load all sub-fragments(tabs).