1

I'm attempting to resolve a previous issue with setting fill parameters:

Thumbnail does not fill_parent as expected

however when I attempt to implement the fix provided in the answer I don't think I've implemented it correctly. When I attempt to do so I get an error regarding the inflation argument stating: The method inflate(int, ViewGroup, boolean) in the type LayoutInflater is not applicable for the arguments (int, int, boolean) however I'm not sure the exact parameter I should use to resolve this in order to get the ImageView to fill correctly.

JAVA:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = mInflater.inflate(R.layout.activity_main, R.layout.list_item_user_video, false);
        }
        UrlImageView thumb = (UrlImageView) convertView.findViewById(R.id.userVideoThumbImageView);

        TextView title = (TextView) convertView.findViewById(R.id.userVideoTitleTextView); 
        final Video video = videos.get(position);
        thumb.setImageDrawable(video.getThumbUrl());
        title.setText(video.getTitle());

        return convertView;
    }

ERROR:

The method inflate(int, ViewGroup, boolean) in the type LayoutInflater is not applicable for the arguments (int, int, boolean)

ERROR LOCATION:

convertView = mInflater.inflate(R.layout.activity_main, R.layout.list_item_user_video, false);

Community
  • 1
  • 1
user3063132
  • 133
  • 2
  • 14

3 Answers3

4

The second parameter to inflate() needs to be a ViewGroup. You are passing an int. Presumably, the second parameter should be parent.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • does convertView = mInflater.inflate(R.layout.activity_main, convertView, false); seem correct? – user3063132 Dec 04 '13 at 14:52
  • 1
    No, it should be `parent`. From the docs about the root parameter: *Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)* – Jeffrey Klardie Dec 04 '13 at 14:53
  • A valid value for you MAY be "this" which means the view you are trying to inflate belongs to this viewgroup. – VJ Vélan Solutions Dec 04 '13 at 14:55
  • convertView = mInflater.inflate(R.layout.list_item_user_video, this, false); results in The method inflate(int, ViewGroup, boolean) in the type LayoutInflater is not applicable for the arguments (int, VideosAdapter, boolean) – user3063132 Dec 04 '13 at 14:59
  • second argument should be `parent`. – Jeffrey Klardie Dec 04 '13 at 15:00
  • Thanks! convertView = mInflater.inflate(R.layout.list_item_user_video, parent, false); resolved the issue! I'm still unable to fill_parent on the image (which is the issue which lead me here) though: http://stackoverflow.com/questions/20361399/thumbnail-does-not-fill-parent-as-expected – user3063132 Dec 04 '13 at 15:02
  • 1
    @JeffreyKlardie: You're absolutely right; I am a moron. I have fixed my answer. Thanks! – CommonsWare Dec 04 '13 at 15:05
1

You should put the parentview in the second argument of the methods signature - that is

 mInflater.inflate(R.layout.activity_main, parent, false);

where parent is the ViewGroup

Björn Hallström
  • 3,775
  • 9
  • 39
  • 50
  • Sorry... commonsware beat you to the punch - if you'd like an easy answer I'm still unable to fill_parent on the image (which is the issue which lead me here): http://stackoverflow.com/questions/20361399/thumbnail-does-not-fill-parent-as-expected – user3063132 Dec 04 '13 at 15:03
1

As user2365568 points out, you should pass parent as the root parameter. The other answers indicate you should pass null or the convertView, which is wrong.

Check out this article about layout inflation, and why the root parameter is important: http://www.doubleencore.com/2013/05/layout-inflation-as-intended/

Jeffrey Klardie
  • 3,020
  • 1
  • 18
  • 23