I'm using Picasso to display many small ImageViews in a RecyclerView. The ImageViews change their Image for 500 milliseconds when I click on them and change it back when the handler with 500 milliseconds end.
This is the code:
Picasso.get().load(imageResources[position]).into(holder1.itemImageView);
holder1.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
final Context context = v.getContext();
Picasso.get().load(pressedResource[position]).into(holder1.itemImageView);
new Handler().postDelayed(new Runnable() {
public void run() {
Picasso.get().load(imageResources[position]).into(holder1.itemImageView);
}
}, 500);
new Thread(new Runnable() {
@Override
public void run() {
EventHandlerClass.startMediaPlayer(v, soundID);
}
}).start();
}
});
I use Picasso to prevent my app from getting OutOfMemory crashes. The Image Dissapears for like 10 milliseconds, then changes to the other image, after the 500 milliseconds it dissapears again and then it changes back to the default image. It only dissapears for the first time I click on one of the Images, after that it works without dissapearance. I think this happens because Picasso is loading the image too slow. Is there a way to first load the image and display it when I click on the button?
Here is a GIF which shows how it looks like: https://media.giphy.com/media/STlGbpXvT8B9iBvnQS/giphy.gif In this case it only dissapeared once but sometime it dissapeares twice with one click.
The Images are all 200x200 and around 8kb. The format is .WEBP
How can I prevent this?