Android uses listview to refresh pages (thread sleep simulation)

When there is too much data to display, in order to better improve user perception, pagination will be used to refresh the display in many apps, such as browsing news. When you slide down to the last item of the current listview, you will be prompted to refresh and load, and then load the updated content. This process is roughly divided into the following steps:

1. Current activity implements onscalllistener;

2. Method of realizing interface;

3. Register listview for rolling monitoring;

4. The adapter (customized or Android built-in) fills in data for each item;

5. After obtaining the data after the second page, the adater adds the data and refreshes notifydatesetchanged(); (handler is required)

Now let's simulate the implementation of listview page refresh through thread sleep (10 pieces of information are loaded each time, and sliding down will refresh and load pages)

Display effect (refresh is enabled after ten items are displayed, and an example of browsing with alertdialog is added):

Listview layout activity in layout_ Main.xml file:

Item in layout (fill each row of listview) layout item.xml file:

Page refresh prompt layout (footer) login in layout_ Item.xml file:

Custom object classes in Java (each news has a corresponding title and content)

Function implementation class in Java (by implementing onscrolllistener interface)

So far, the paging refresh source code of listview has been fully displayed. Personally, I think the core of realizing this function is to judge whether to reach the last item in the current listview (including footer refresh prompt) and understand the state of scrollstate. Understanding these two points will get twice the result with half the effort.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>