I have implemented default fragment pager adapter for three fragments. And its working fine but what I want is to swap fragment from inside one of those three fragment(Not from activity). I have tried to search for ans but couldn't find it.
EDIT: I am using DEFAULT tablayout activity with slider.I am not using custom fragmentPagerAdapter. Below class is implemented in main activity.
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
return new FragmentTest1();
case 1:
return new FragmentTest2();
case 2:
return new FragmentTest3();
default:
return null;
}}
@Override
public int getCount() {
return 3;
}
MainActivity onCreate method of main activity is given below...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slider);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
FragmenTest1 From FragmentTest1 I want to make transition to another fragment on action.
public class FragmentTest1 extends android.support.v4.app.Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab_log, container, false);
Button button = rootView.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
return rootView;
}
}
I want to make transition on click event to another fragment...