Andorid, Glide shows the wrong image for about one second

So, I use the Glide library to upload images from the URL that I get from Graph Request (Facebook). It is used in the RecyclerAdapter. When I scroll, each ImageView shows the wrong image for about one second, and then corrects it. Here is the code:

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {

    ImageView main_image = viewHolder.main_image,

    getEventCover(position, main_image);

        }

private void getEventCover(int position, final ImageView img){

        GraphRequest request = GraphRequest.newGraphPathRequest(
                AccessToken.getCurrentAccessToken(),
                event.get(position).getEventID(),
                new GraphRequest.Callback() {
                    @Override
                    public void onCompleted(GraphResponse response) {

                        JSONObject data = response.getJSONObject();

                        try {
                            JSONObject cover = data.getJSONObject("cover");
                            String source = cover.getString("source");

                            Glide.with(fragment)
                                    .load(source)
                                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                                    .centerCrop()
                                    .into(img);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
        );

        Bundle parameters = new Bundle();
        parameters.putString("fields", "cover");
        request.setParameters(parameters);
        request.executeAsync();
}
+4
source share
2 answers

Your "problem" is that the ones you use are ImageViewprocessed from the previous lines (which disappear when scrolling). Thus, your ImageViewin onBindViewHolderalready contains the previous image.

, (GraphRequest Glide) .

, ImageView getEventCover. , :

main_image.setImageResource(android.R.color.transparent);
+3
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {

    ImageView main_image = viewHolder.main_image,
    main_image.setImageURI(null);
    getEventCover(position, main_image);

        }

() () , . , ImageView . .

+2

All Articles