Paul
Paul

Reputation: 6176

R.id parent of R.layout : how to do this?

how can an id be a parent of a layout folder?

in this code, it seems that R.id.layout_root is a parent of R.layout.custom_dialog, how can i do this in my folder tree?

View layout = inflater.inflate(R.layout.custom_dialog,
                (ViewGroup) findViewById(R.id.layout_root));

Thanks

Upvotes: 0

Views: 710

Answers (1)

gwvatieri
gwvatieri

Reputation: 5183

I don't know if I understood well your question. Anyway, the inflate method that you are using simply inflates that custom_dialog layout as child of en existent VievGroup. You don't have to do anything in your folders, there is no relationships between that code and the directory hierarchy.

These are the 2 parameters that the method gets (from the doc):

resource    ID for an XML layout resource to load (e.g., R.layout.main_page)
root        Optional view to be the parent of the generated hierarchy.

This small example maybe clarifies your doubts. This line of code:

LinearLayout lLayout = inflater.inflate(R.layout.buttons, R.id.layout1);

is equivalent to:

Button b = (Button) inflater.inflate(R.layout.buttons, null);
LinearLayout lLayout = (LinearLayout)findViewById(R.id.layout1);
lLayout.addView(b);

Upvotes: 1

Related Questions