1

I m working on tabs . i m using view pager . and assigned fragment its working but i want to change content or replace fragment but i want to stay on same tab. suppose i m in a tab when i click button on a tab i want to change fragment on tab. but tab should not to be change.how to do .

ViewPagerAdapter adapter = ne  ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new General(), "General");
    adapter.addFragment(new Educat(), "Education");
    adapter.addFragment(new Profetiona(), "Experience");
    adapter.addFragment(new Skills(), "Skills");

so when i m in tab 0 which is general tab there is one button when i click i want to replace general fragement to infoFragement in tab 0 . i dont want to swipe tab i want only change the content or load new fragement

androidking
  • 207
  • 5
  • 17

1 Answers1

0

You can use nested fragment. For example in your General fragment you can load ChildFragment1 at the beginning, then when after the button click replace it with ChildFragment2.

fragment_general.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="vertical">

    <View
        android:id="@+id/view_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</FrameLayout>

GneralFragment.java

//Call this at the beginning
private void loadChildFragment1(){
    getChildFragmentManager()
                    .beginTransaction()
                    .replace(R.id.view_container,
                            new ChildFragment1()
                    .commit();
}

//Call this after the click
private void loadChildFragment2(){
    getChildFragmentManager()
                    .beginTransaction()
                    .replace(R.id.view_container,
                            new ChildFragment2()
                    .commit();
}
Jameido
  • 1,344
  • 1
  • 11
  • 21