I am using the SherlockFragments library for the sliding menu.I have list of items as menu when I click on item fragment get opened as an activity but it is a fragment.Now
This is the code I use to switch fragments inside a view:
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace([viewId], fragment, tag);
fragmentTransaction.addToBackStack(tag);
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.commit();
You can try this also:-
public void ButtonClick(View view) { Fragment mFragment = new YourNextFragment(); getSupportFragmentManager().beginTransaction() .replace(R.id.content_frame, mFragment ).commit(); }
FragmentManager fragmentManager = getFragmentManager();
fragmentManager
.beginTransaction()
.replace(R.id.frame_container,
new TeacherFragment()).commit();
FragmentTransaction fragmenttransaction = getSupportFragmentManager().beginTransaction();
FirstFragment regcomplainfragment = new FirstFragment();
fragmenttransaction.replace(R.id.content_frame, regcomplainfragment).addToBackStack("tag");
fragmenttransaction.commit();
//Below is the example
//In first Fragment
Fragment fragment = new YourFragmentClassName();
FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); android.support.v4.app.FragmentTransaction ft= fragmentManager.beginTransaction();
ft.replace(R.id.flContent, fragment);
Bundle args = new Bundle();
// Pass the values what you want to send to next fragment
args.putInt("Year", rYear);
args.putString("Month", rMonth);
args.putInt("Industry", rIndustry);
fragment.setArguments(args);
ft.commit();
//In Second Fragment
//In onCreateView Method get the values
int strYear= getArguments().getInt("Year");
String strMonth = getArguments().getString("Month");
strIndustry= getArguments().getInt("Industry");
//That's it very simple
It's simple Only three line code...
Fragment fragment = new SalesFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();