I'm showing images from server with Google Paging Library. When I show images from Localhost, it work perfect but with live server it's image is flickering. I tried to sleep Localhost for 2s to delay response but localhost's images were not flickering. My problem is same as image-flickering-while-scrolling-in-recyclerview question. But i'm not using asynctask so can't use it's answer.
Recyclerview Adapter.
public class ItemAdapter extends PagedListAdapter<Item, ItemAdapter.ItemViewHolder> {
private Context mCtx;
ItemAdapter( Context mCtx) {
super(DIFF_CALLBACK);
this.mCtx = mCtx;
}
@NonNull
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mCtx).inflate(R.layout.recyclerview_users, parent, false);
return new ItemViewHolder(view);
}
private static DiffUtil.ItemCallback<Item> DIFF_CALLBACK =
new DiffUtil.ItemCallback<Item>() {
@Override
public boolean areItemsTheSame(Item oldItem, Item newItem) {
return oldItem.id == newItem.id;
}
@Override
public boolean areContentsTheSame(Item oldItem, Item newItem) {
return oldItem.equals(newItem);
}
};
@Override
public void onBindViewHolder(@NonNull ItemViewHolder viewHolder, int position) {
Item item = getItem(position);
final ItemViewHolder holder = (ItemViewHolder) viewHolder;
holder.image_date.setText(item.getDate());
GlideApp
.with(mCtx)
.asBitmap()
.load(item.getThumb())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(holder.imageview);
}
class ItemViewHolder extends RecyclerView.ViewHolder {
TextView image_date, image_weight, imageHit;
ImageView imageView, imageView2;
ProgressBar progressBar;
ItemViewHolder(View view) {
super(view);
image_date = itemView.findViewById(R.id.image_date);
image_weight = itemView.findViewById(R.id.image_weight);
imageHit = itemView.findViewById(R.id.hit);
imageView = (ImageView) itemView.findViewById(R.id.thumb_image);
imageView2 = itemView.findViewById(R.id.thumb_image2);
progressBar = itemView.findViewById(R.id.progressBarThumb);
}
}
}
I'm using this method. https://www.simplifiedcoding.net/android-paging-library-tutorial. When i use same code as this method. IT work fine. Problem happen when i changed code as my use. P.S.- Problem is when data is loading. Once data is loaded, it works fine.