user1159517
user1159517

Reputation: 6320

What is difference between LayoutInflater and setContentView in android?

I'm trying to develop an android app and looking at various tutorials, it seems people are using setContentView as well as LayoutInflater at many places. What is the difference between these two and when should i use LayoutInflater instead of setContentView?

Upvotes: 0

Views: 1045

Answers (2)

Juan
Juan

Reputation: 5589

I think setContentView will set the specified layout as the layout of the Activity your are running, while LayoutInflater can be used in situations where you need to use a layout but not necessarily use that layout as the layout for the Activity itself.

For example you may want to inflate a custom layout for the listview's items, which has nothing to do with the layout of the Activity. In this case you will use a LayoutInflater.

Upvotes: 3

jyoonPro
jyoonPro

Reputation: 1681

setContentView is for Activities, and LayoutInflater is used in Fragments.

Upvotes: 0

Related Questions