You have te use another Fragment
in order to do that. You need to create that Fragment
and then replace the old one with the FragmentTransaction
and if you want to use the "back" button you need to add the new fragment to the Backstack
.
If these ListFragment
are quite different in terms of data, I'd have 2 fragment classes (e.g. : FirstListFragment, SecondListFragment).
Here's some code from an App I worked on :
// Here I get the FragmentTransaction
FragmentTransaction ft = getFragmentManager().beginTransaction();
// I replace it with a new Fragment giving it data. Here you need to tell
// the FragmentTransaction what (or actually where) and by what you want to replace.
ft.replace(R.id.fraglist, new ModuleFragment(lpId, sqId, sqName));
The R.id.fraglist should be defined in your XML layout (except if you programmatically created your layout). It's simply the ID of your default fragment.
// I set the animation
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// I add it to the backstack so I can use the back button
ft.addToBackStack(null);
// Then I finally commit so it happens !
ft.commit();
You can also use a Bundle to parse data like so :
Bundle moduleBundle = new Bundle();
moduleBundle.putString("id", id);
moduleBundle.putString("description", description);
moduleFragment.setArguments(moduleBundle);