How shall I populate my RecyclerView asynchronously? <p><strong>Problem</strong></p> <p>My RecyclerView displays elements with photos. Every photo is being downloaded from the Internet which may take up to few seconds. Hence, I try to avoid blocking the UI thread and I pass the work to a Handler, however, due to RecyclerView's recycling behavior, it shows the images improperly. </p> <p><strong>This is how it looks like:</strong></p> <p>Loads image 1 to list item 1.</p> <p>Loads image 2 to list item 2.</p> <p>I scroll down.</p> <p>Loads image 3 to list item 20.</p> <p>Loads image 4 to list item 21.</p> <p>Loads image 4 to list item 20.</p> <p>Loads image 5 to list item 21.</p> <p>At the end everything is ok, but during the loading process, RecyclerView recycles the ViewHolders with the wrong images!</p> <p><strong>My code</strong></p> <pre><code>mHandler.post(new Runnable() { @Override public void run() { final Uri image = complexFetchingFunction(); activity.runOnUiThread(new Runnable() { @Override public void run() { try { holder.imageView.setImageURI(image); } catch (Exception e) { e.printStackTrace(); } } }); } }); </code></pre> <p><strong>End</strong></p> <p>Handler works on a separate thread. That's sure. I know all these things happen, because I load the images asynchronously and RecyclerView doesn't like it, but otherwise it's painfully slow.</p> <p>Does anyone have a solution?</p>