Eric Dand
Eric Dand

Reputation: 1210

Will the View returned by LayoutInflater.inflate() always also be a ViewGroup?

I'm wanting to add a LinearLayout programmatically to my screen. When I call getlayoutInflater().inflate(R.layout.whatever, null), will the returned View always be also a ViewGroup? What could it ever return that is not a ViewGroup?

Upvotes: 0

Views: 51

Answers (2)

Henry
Henry

Reputation: 43738

The returned view depends on what is defined in the layout as the root view. It can also be a simple view like a TextView so it is not necessarily a ViewGroup.

Upvotes: 2

Niko
Niko

Reputation: 8153

The answer is no. You can check which are ViewGroups from here: http://developer.android.com/reference/android/view/ViewGroup.html

The basic principle is that ViewGroup can contain child Views

For example if you inflate layout which has only ImageView in it. Then that is a View.

Upvotes: 0

Related Questions