Detailed explanation of pulltorefresh pull-down refresh function of Android open source project 2

First look at the renderings:

Here is the use method of pulltorrefreshgridview, which is the same as the previous pulltorrefreshlistview method. Because this open source project is very modular, it is easy to implement. It means that we can operate in the way we used controls before, without considering other problems.

Idea:

1. Write the layout file and put it into the control that can be refreshed by drop-down. 2. Find the control that can be refreshed by drop-down, set the listener, and start an asynchronous task in the refresh method to operate. 3. Get the GridView object through the getrefreshableview() method of this drop-down refresh control, Set the adapter according to the normal operation. 4. Add new data to the header or tail through LinkedList in the asynchronous task

realization:

1. Layout documents

We can see that we can still define the properties of GridView just like using GridView. Of course, you can set exclusive properties through the PTR: namespace

2. Find the control that can be pulled down and refreshed, and set the listener

The listener here is different from that in the previous article. It is two-way. So it's very convenient to monitor sliding operation!

3. Find the GridView to set the adapter

Here, you can also set the content displayed when there is no data in the adapter. The method called is: setemptyview()

4. Execute asynchronous tasks and simulate loading data. This is the same as before

All code in mainactivity.java

Source code download: http://xiazai.jb51.net/201609/yuanma/AndroidGridView (jb51.net).rar

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