2

Updating Image with in Recycleview

I am working on chatapp, when user clicks on imageview in Recycleview, I am downloading image to local storage and then trying to reload with picasso, Then Recycleview is jumping to another position.

Note : Based on my R&D, I understood Imageview required focus while reloading it. I am not sure, Please let me understand what is the best way to reload image in Recycleview in specif position without jumping like how whatsapp is loading images in chatscreen onclick of download.

I am using below method to update specif position.

 notifyItemChanged(position);

And If I try to Reload with below methods then no problem, But OOM(Out of memory) may come while loading from URI

 messageImageView.setImageURI(Uri.fromFile(fileImage));
 messageImageView.setImageResource(R.drawable.icn_conv_clicktodownload);

Problem Case :

Picasso.get().load(fileImage).resize(viewWidth, viewHeight).
                    centerCrop().into(messageImageView);
Guruprasad
  • 931
  • 11
  • 16

1 Answers1

0

Try this...Answer refered from this link..here

// Save state
private Parcelable recyclerViewState;
recyclerViewState = recyclerView.getLayoutManager().onSaveInstanceState();

// Restore state
notifyItemChanged(position);
recyclerView.getLayoutManager().onRestoreInstanceState(recyclerViewState);
Sachin Soma
  • 3,432
  • 2
  • 10
  • 18
  • Can you please explain why should I save state of recyclerView to update image in Viewholder..? – Guruprasad Jun 06 '19 at 06:38
  • because after notifyItemChanged() your recyclerview scrolls to top position. – Sachin Soma Jun 07 '19 at 07:17
  • I tried same, But it did not help me, I understood while reloading picture in viewholder its loosing its focus. i am trying to understand how can i get focus of imageview..? – Guruprasad Jun 07 '19 at 08:11