I'm new to the concept of Fragments
In the video I was watching, they used this piece of code:
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentById(R.id.my_container);
if(fragment == null){
fragment = new FragmentMain();
fragmentManager.beginTransaction()
.add(R.id.my_container, fragment)
.commit();
}
To create a Fragment
via java.
In
findFragmentById
they passed in aFrameLayout
(my_container) rather than aFragment
. I read in the docs that you can pass in a container id, but it confuses me how it will initialize it as aFragment
. How does this work?Should I use
FragmentManager
? I read in the docs that it's deprecated.
Thanks!