0

I'm trying to add a ProgressBar at the bottom of my RecyclerView but the problem is detecting the bottom of the RecyclerView.

My getItemViewType always return 1, because list.get(position) is always not null even when I scroll to the bottom of the RecyclerView, here's my code

 @Override
 public int getItemViewType(int position) {
  return list.get(position) != null ? 1 : 0;
 }

Can any body point the problem here?

Abdennacer Lachiheb
  • 4,388
  • 7
  • 30
  • 61

1 Answers1

1

You shouls override getItemCount method with

return list.size() + 1;

and replace

return list.get(position) != null ? 1 : 0;

with

return (list.size() == position) ? 1 : 0;

then you should check viewType (0 is your cell and 1 is loading one) in onCreateViewHolder method and use proper ViewHolder (refer this link for example).

Also there is a better way to have boolean value to track whether additional data is available to prevent showing loading cell if the last page of data was already uploaded:

@Override
int getItemCount () {
    return list.size() + moreDataAvailable ? 1 : 0;
}
Community
  • 1
  • 1
UneXp
  • 1,574
  • 2
  • 16
  • 31