0

I am trying to build a fragment (Fragment0) with a TabLayout. When I click on Tab1, I want to navigate to Fragment1. When I click on Tab2, I want to navigate to Fragment2. When I click on Tab3, I want to navigate to Fragment3.

I don't want to use a ViewPager.

How could I achieve this?

Praveen P.
  • 976
  • 2
  • 11
  • 23

1 Answers1

1

You can use ViewPager and disable the scrolling like this: https://stackoverflow.com/a/7814054/10002974

Also, if you don't want to use that then you can try this:

Fragment fragment = new YourFragment();

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(R.id.contentFragment, fragment);
transaction.commit();
Piyush Maheswari
  • 635
  • 3
  • 18