I'm using Picasso Library in Custom RecyclerView adapter. In onBindViewHolder(), binding to view holder is showing error

public class ViewHolder extends RecyclerView.ViewHolder
    {
        ImageView image_view;
        public ViewHolder(View itemView)
        {
            super(itemView);
            image_view = (ImageView) itemView.findViewById(R.id.background);
        }
    }

 @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int 
    listPosition)
    {
        String abcd = "http://localhost/tack/poster1.jpg";
        Picasso.with((Context) mContext).load(abcd).into(holder.image_view);
    }

Showing Error - cannot resolve symbol 'image_view'

I need to bind the image from URL to ImageView

1 Answers

0
Mr.vicky On Best Solutions

Please have a look at my adapter and compare it with yours and then update the required methods and parameters as you need.

public class FollowerAdapter1 extends RecyclerView.Adapter<FollowerAdapter1.MyViewHolder> {

    private Context context;

    public FollowerAdapter1(Context context) {
        this.context=context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.custom_followers,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder( final MyViewHolder holder, final int i) {
                Glide.with(context)
                        .load("YOUR IMAGE URL")
                        .apply(RequestOptions.placeholderOf(R.drawable.placeholder))
                        .into(holder.ivfollower);

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

    @Override
    public int getItemCount() {
            return 10;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView ivfollower,ivfollow;

        public MyViewHolder(View itemView) {
            super(itemView);
            ivfollower=itemView.findViewById(R.id.iv_follow_profile);

        }
    }
}