I study fragments, but I do not understand the meaning of why fragments require a container.
As I understand it, the work on fragments is as follows:
FragmentActivity setContentview refers to an XML file that determines where fragments will be located.
FragmentActivity instantiates fragments
Then assigns the fragment to the container.
Then displays the FragmentManager.
The actual fragment class then inflates the layout, and it is this layout that contains all the components of the application user interface.
(please correct me if I miss something here, because now I was just studying).
So, for some reason, we need the purpose of the container, because in all the examples that I saw, this is just an empty XML document in a format document.
Can different fragments use the same container (with its just XML file RelativeLayout)?
So in the example provided by google http://developer.android.com/training/basics/fragments/creating.html
They have a ListFragment, and when an item is selected using the CallBack interface, we eventually return to this line of code:
// 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 transaction.replace(R.id.fragment_container, newFragment);
My other question is:
1) Why does this line of code not replace the ListFragment fragment (left fragment) with the article fragment. Since when it was initialized, we see:
getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, firstFragment).commit();
Instead ... the ListFragment stays on the left and the right Fragment is updated. But the fragment_container container belongs to firstFragment, it is a ListFragment. And this is not the one that is being updated.
Do you see why I have a question? This is not explained in the textbook.