How can I create a list where when you reach the end of the list I am notified so I can load more items?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- how to split a list into a given number of sub-lis
- Listening to outgoing sms not working android
Here is a solution that also makes it easy to show a loading view in the end of the ListView while it's loading.
You can see the classes here:
https://github.com/CyberEagle/OpenProjects/blob/master/android-projects/widgets/src/main/java/br/com/cybereagle/androidwidgets/helper/ListViewWithLoadingIndicatorHelper.java - Helper to make it possible to use the features without extending from SimpleListViewWithLoadingIndicator.
https://github.com/CyberEagle/OpenProjects/blob/master/android-projects/widgets/src/main/java/br/com/cybereagle/androidwidgets/listener/EndlessScrollListener.java - Listener that starts loading data when the user is about to reach the bottom of the ListView.
https://github.com/CyberEagle/OpenProjects/blob/master/android-projects/widgets/src/main/java/br/com/cybereagle/androidwidgets/view/SimpleListViewWithLoadingIndicator.java - The EndlessListView. You can use this class directly or extend from it.
The key of this problem is to detect the load-more event, start an async request for data and then update the list. Also an adapter with loading indicator and other decorators is needed. In fact, the problem is very complicated in some corner cases. Just a
OnScrollListener
implementation is not enough, because sometimes the items do not fill the screen.I have written a personal package which support endless list for
RecyclerView
, and also provide a async loader implementationAutoPagerFragment
which makes it very easy to get data from a multi-page source. It can load any page you want into aRecyclerView
on a custom event, not only the next page.Here is the address: https://github.com/SphiaTower/AutoPagerRecyclerManager
I've been working in another solution very similar to that, but, I am using a
footerView
to give the possibility to the user download more elements clicking thefooterView
, I am using a "menu" which is shown above theListView
and in the bottom of the parent view, this "menu" hides the bottom of theListView
, so, when thelistView
is scrolling the menu disappear and when scroll state is idle, the menu appear again, but when the user scrolls to the end of thelistView
, I "ask" to know if thefooterView
is shown in that case, the menu doesn't appear and the user can see thefooterView
to load more content. Here the code:Regards.
One solution is to implement an
OnScrollListener
and make changes (like adding items, etc.) to theListAdapter
at a convenient state in itsonScroll
method.The following
ListActivity
shows a list of integers, starting with 40, adding items when the user scrolls to the end of the list.You should obviously use separate threads for long running actions (like loading web-data) and might want to indicate progress in the last list item (like the market or gmail apps do).
May be a little late but the following solution happened very useful in my case. In a way all you need to do is add to your ListView a
Footer
and create for itaddOnLayoutChangeListener
.http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
For example:
This event fires once when a footer becomes visible and works like a charm.
At
Ognyan Bankov GitHub
i found a simple and working solution!It makes use of the
Volley HTTP library
that makes networking for Android apps easier and most importantly, faster. Volley is available through the open AOSP repository.The given code demonstrates:
For future consistence i forked Bankov's repo.