Strange behaviour of images in RecyclerView

后端 未结 3 1065
忘掉有多难
忘掉有多难 2020-12-23 09:52

I am using android.support.v7.widget.RecyclerView to show simple items containing text and in some cases also images. Basically I followed the tutorial from here https://dev

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 10:37

    Not sure if people still have issues with this, but the if statement did not work for me. What did work for me is this:

    Using an override on this method in the adapter

    @Override
        public int getItemViewType(int position) {
            return position;
        }
    

    followed by calling the if statement based on this for the image itself within the onBindViewHolder, like so:

    int pos = getItemViewType(position);
                if(theList.get(pos).getPicture() == null) {
    
                    holder.picture.setVisibility(View.GONE);
                } else {
    
                    Picasso.with(context).load(R.drawable.robot).into(holder.picture);
                }
    

    I am using Picasso but it should work with any other else situation. Hope this helps someone!

提交回复
热议问题