2

I'm trying to change the visibility of ImageView (Visible/Invisible), depending on the RecyclerView item state (Selected/Not selected), so if the item selected, I want to make ImageView visible, something like the below picture :

I wrote the following code to make this true :

    private int selectedItem = 0;

    public class ViewHolderFilters extends RecyclerView.ViewHolder implements View.OnClickListener {

        CircleImageView img;
        CircleImageView selected_effect;

        ViewHolderFilters(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id._imageView);
            selected_effect = itemView.findViewById(R.id.selected_effect);
            img.setOnClickListener(this);
        }

        void onBindView(int position) {
            final String s = spacecrafts.get(position);
            Glide.with(c)
                    .asBitmap()
                    .load(s).centerCrop()
                    .apply(new RequestOptions().placeholder(R.drawable.transparent_icon))
                    .into(new CustomTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                            progress.setVisibility(View.GONE);
                            img.setImageBitmap(setEffectLight(c, resource, getThumbnail(bitmapOriginal)));
                        }

                        @Override
                        public void onLoadCleared(@Nullable Drawable placeholder) {

                        }
                    });
            if (selected_item == position) {
                selected_effect.setVisibility(View.VISIBLE);
            } else {
                selected_effect.setVisibility(View.INVISIBLE);
            }
        }

        @Override
        public void onClick(View view) {
            monShaderRecyclerViewClickListener.onClick(view, spacecrafts.get(getAdapterPosition()));
            selected_item = getAdapterPosition();
            notifyDataSetChanged();
        }
    }

MY ISSUE:

Each time I select an item, the notifyDataSetChanged() method brings an animation with it, which looks not smooth and nice.

How I can disable the animation and update the item?

1 Answers1

2

There is a default item animator on recycler view. You can disable it when creating the recycler view inside your view/fragment/activity:

((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
Ian Medeiros
  • 1,746
  • 9
  • 24