I'm working on a simple Android App as a self-learning Project. I've got a lot of it functioning, and I have a main Activity
which has a FrameLayout
and some RecyclerView
and FloatingActionButton
stuff going on inside of it.
However, I want to make one of my buttons in my NavigationDrawer
open a different view in the FrameLayout using Fragments
. Is there a way to do this, sort of making a new Fragment for the RecyclerView
and the other stuff and putting the RecyclerView
and FloatingActionButton
in there?
I tried doing something like this (when the appropriate NavigationDrawer
button was clicked):
statsFragment = new StatsFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.rootLayout, statsFragment);
transaction.addToBackStack(null);
transaction.commit();
But this caused my app to crash. Any pointers?