0

I am trying to start a fragment in the activity by using the following method:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

getFragmentManager().beginTransaction()
.add(android.R.id.content, createFrag2()).commit(); //createFrag is a function that adds some values to the bundle and returns a fragment 

What I was told was to be careful when using "android.R.id.content". I was told that if I use the fragment as the top level content view of the activity, then you can use. And if it's not a top level content view, then I will need to create a custom layout and setting it's ID.

So the question, what is a top level content view in Android? Is it the main/first layout in the XML? What is the relation to the root view?

I know that the setContentView function will set the activity's content to that of the view specified by the XML. But, I am trying to understand it from the perspective of that statement above("top level content view of the activity").

Thanks!

Bobby_th
  • 91
  • 7
  • hmmm, that does not really explain that well. They say that it's the root element view. So what is this root element view? Is view the XML file they are talking about or the layout(linear, relative etc) and listView, editText in the XML file? Like if i have multiple fragments with XML file, what would be the root view/Top level content view? – Bobby_th Jan 26 '16 at 20:15
  • http://stackoverflow.com/a/12887919/534471 – Emanuel Moecklin Jan 26 '16 at 20:20
  • I guess this is more of the answer for this question, so root view and content views are the same thing: http://stackoverflow.com/questions/12166905/what-is-a-rootview – Bobby_th Jan 27 '16 at 03:02

0 Answers0