0

I have a RecyclerView which is essentially endless, and it loads data 10 items at a time using a cursor. I got a circular progress bar to show up at the bottom when items are still loading, however, if I stop the internet connection, the progress bar continues to spin on forever. How would I implement a message that replaces the circular progress bar if there is no internet connection?

A good example of what I'm trying to do is what the Play Store uses, as well as reddit is fun.

Progress bar while loading content (Progress bar while loading content)

"No internet connection" message to replace progress bar ("No internet connection" message to replace progress bar)

The code I used for my progress bar is very similar to the way @vilen implemented it here

Community
  • 1
  • 1
rohan
  • 129
  • 2
  • 17
  • Can you show the code for showing the progress bar. You should be able to do the same but to show a linear layout with the message. – Nicolas May 08 '17 at 20:46
  • Very similar to the answer here http://stackoverflow.com/questions/30681905/adding-items-to-endless-scroll-recyclerview-with-progressbar-at-bottom – rohan May 08 '17 at 20:52

1 Answers1

0

You can change the ProgressBar layout with another layout that has both the ProgressBar and a LinearLayout with the icon, message and retry button. In onBindViewHolder, show only progress bar if there is internet connection, otherwise only show the LinearLayout. In your activity, when you detect a change of internet connection, call adapter.notifyItemChanged(adapter.getItemCount()-1) to update the last item.

You can see this answer for how to detect connectivity change.

Community
  • 1
  • 1
Nicolas
  • 5,182
  • 2
  • 22
  • 58