Android: how to move from one fragment to another in Tab?

The application has Tabs, Tab A, and Tab B buffers that expand the fragment. Now my question is: when I click on the list item of tab B, the new fragment C should be called on the tab. With the following code I can call Fragment C, but not inside the tab.

Intent intent = new Intent();
intent.setClass(getActivity(), C.class);
startActivity(intent);

When I use actions, I can solve the problem using ActivityGroup. Is there a similar way in fragments.

+3
source share
3 answers

try using this code in a list of list items.

private void stackAFragment() {
            Fragment f;
            f = new MedicationOrderFragment();
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.main_details_fragment_container, f);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            ft.addToBackStack(null);
            ft.commit();
        }
+4
source

try replacing the snippet:

protected void replaceDataFragment(Fragment fragment){
    android.app.FragmentTransaction ftr = getFragmentManager().beginTransaction();
    ftr.replace(R.id.data<id of your fragment layout>, fragment);
        ftr.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ftr.commit();   
    }
0
source

. :

getSupportFragmentManager().beginTransaction().replace(
R.id.my_container_in_xml, new MyFragment(), 0).commit();
0

All Articles