Simple implementation of Android listview paging

Simple implementation of Android listview paging

Paging is essential in development and application. So, let's implement the paging function now.

First, think about the steps to achieve it,

1. Implemented components, 2. Initialize the data of the first page, 3. Bottom layout, 4. Conditions for loading data, 5. Obtain the data of the next page.

With ideas, we can realize it step by step. Let's think about what components we use to implement it. We know that we often use listview or recyclerview to initialize data. We are preparing data through a for loop. In the bottom layout, we can directly display the progressbar control and a textview. As for the loaded data, we use onscrolllistener to listen for sliding events, and then when the loading conditions are met, we can load the data of the next page.

Let's take a look at the listview implementation:

Custom listview (loadlistview. Java):

Bottom layout listloader.xml

Source code of mainactivity.java:

LoadAdapter.java

activity_ main.xml:

item_ news.xml:

In fact, as long as you master the callback of onscrolllistener, it's very simple. Recyclerview has also appeared for a long time. Slowly, recyclerview will replace listview, so listview paging seems to be out of date. What we want to know is how recyclerview implements paging. However, we know that recyclerview cannot add the head and bottom, so we need to implement a recyclerview that can add the head and bottom by ourselves.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>