KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am learning fragments but I am failing to understand the significance behind why fragments requires a Container. The way I understand Fragments work is as follows : FragmentActivity setContentview refers to a xml file which defines where fragments would be located. FragmentActivity creates instance of the fragments Then assigns fragment to container. FragmentManager then displays them. The actual Fragment class then inflates a layout, and it is this layout which contains all of the applications UI components. (please correct me if I miss something here because I am only learning at the moment). So why is the purpose of the Container why do we even need since in all the examples I have seen it is just a blank relative layout xml document. Can different fragments share the same Container (since its just a RelativeLayout xml file)? So in the example provided by google http://developer.android.com/training/basics/fragments/creating.html They have a ListFragment and when item is selected through the use of the CallBack interface we eventually get back 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 (left side Fragment) with the article fragment. Since when it was initialised we see: getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, firstFragment).commit(); Instead ... the ListFragment remains on the left and the right Fragment is updated. But the container fragme
Tags (comma-separated)
Save Edits
Cancel