navigate from one fragment to another android
Fragment fragment = new tasks(); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();
Here is what the above code is Doing:
1. Create a new instance of the fragment you want to switch to.
2. Get the FragmentManager and start a transaction.
3. Replace whatever is in the fragment_container view with this fragment,
and add the transaction to the back stack so the user can navigate back
4. Commit the transaction.