Search code examples
androidandroid-recyclerviewandroid-glidenotifydatasetchangedlinearlayoutmanager

Dynamic height Glide ImageView inside RecyclerView Blinking on calling notifydatasetchanged?


Am creating a RecyclerView to show some images and text, then user can bookmark rows of RecyclerView. Images of the RecyclerView are match parent on width and height will be wrap_content. On clicking on bookmark, adapter calls notifydatasetchanged in RecyclerView. My issue is that after calling notifydatasetchanged changed, RecyclerView blinking its images by height.

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
            if (holder instanceof VHITEM) {
                final VHITEM VHitem = (VHITEM) holder;
                Glide.with(mContext)
                        .load(articleDataList.get(position).SourcePath)
                        .asBitmap()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .placeholder(R.drawable.defaultimage)
                        .error(R.drawable.defaultimage)
                        .dontAnimate()
                        .into(VHitem.imageViewTagPic); 
            }
        }

OnButton Click

    VHItem.imageViewAddRemoveBookmark.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
    notifyDataSetChanged(); }
    }

RecyclerView configuration

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linearLayoutManager);

Solution

  • It's not because of glide, if item data changed call notifyitemchanged(position,payload) and then override onBindViewHolder 3 argument method