3

There seems to be a lot of post on how one can scroll up for more posts and I have posted a question on this before: Adding items to Endless Scroll RecyclerView with ProgressBar at bottom

However, I have a question on deleting items in a list on recyclerview. You have an android app which fetches 5 items from the database server in a page. As soon as it fetches it, you start deleting items one by one.

The list recyclerview scrolls up but the OnScrollListener is not called as you haven't really "scrolled".

How do I address this problem when I want to add on more items to my list as my delete start eliminating items from the top?

Community
  • 1
  • 1
Simon
  • 18,312
  • 22
  • 130
  • 197
  • What about when you save how many items get deleted and when a specific count get reached you fetch new items and reset the counter? Would that be a solution? – mrtn Jun 14 '15 at 19:46
  • I'm unsure as the scrollListener seems to keep track of the current page. The easiest would be to "mock" a call to the scrollListener but don't know how that could be done. – Simon Jun 14 '15 at 19:51
  • Calling `mRecyclerView.scrollBy(0,0);` will cause a call to `onScrollChanged()` and the `RecyclerView` will be invalidated. – Markus Rubey Jun 14 '15 at 20:23
  • @Simon Were you able to find solution to this? – Shobhit Puri Nov 26 '18 at 22:37
  • I posted this question a long time ago ... but I would imagine you can build in logic where when the items on the screen is 5 or less and u want to delete an item, u can call the api to download the next page of items so that the list is increased before the deletion happens. That way u will always have more items to scroll downwards and trigger onscrolllistener. – Simon Nov 28 '18 at 08:10

1 Answers1

-1

when deleting each item call

recyclerView.smoothScrollToPosition(0); 

it works perfectly

jayant singh
  • 792
  • 11
  • 16