0

I am trying to include a new layout on an event. For that I am using LayoutInflater in That event listener. But the problem is, LayoutInflater.inflate() function expect its parameters to be (Int) ResourceId, ViewGroup. I am unable to figure out what to use as ViewGroup in the event listener. this refers to that event listener. parent and item are both views, not ViewGroups. Please help.

Sourabh
  • 1,757
  • 6
  • 21
  • 43
  • Usually you send the view, that the view you are inflating is gonna be in (it's parent). A view can also be a ViewGroup, by inheriting the class. So if your view is for example, A linear-, relative- or framelayout, they are also a ViewGroup, and you should just cast them like this (ViewGroup)view. See here for more info: http://developer.android.com/reference/android/view/ViewGroup.html (click on 'Known Direct Subclasses', to view which other views are also ViewGroups). – Lauw Oct 23 '13 at 23:12

1 Answers1

1

If you're attaching it to your activity, use that. If, however, you want a floating view, make your call as follows:

View view = inflater.inflate(resourceId, null, false);

This will create it and allow you to add it as a view to whatever you please.

Andrew Schuster
  • 3,229
  • 2
  • 21
  • 32