K.Sopheak
K.Sopheak

Reputation: 23144

What is the different between setContentView and getLayoutResource in android?

Generally, when we want to load android layout we use setContentView(view) in onCreate function. I saw another function getLayoutResource() which get load layout too. I have read getLayoutResource, but I don't understand about it.

What is the different between them?

Upvotes: 1

Views: 284

Answers (1)

ishmaelMakitla
ishmaelMakitla

Reputation: 3812

I am not sure where you read about getLayoutResource() as loading layout too? The getLayoutResource() method gets the layout resource that will be shown as the View. The setContentView(view) on the other hand sets the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.

So for instance, if you had invoked setContentView(R.layout.my_awesome_layout);, then calling getLayoutResource() should return the Integer identifier for R.layout.my_awesome_layout;

You can read more on setContentView(android.view.View)

I hope this helps.

Upvotes: 2

Related Questions