Implementation of listview drop-down refresh of Android custom control

I've learned custom controls for a long time and found that I always forget them, so I plan to use a blog to record my knowledge points.

Today, we customize the listview to achieve drop-down refresh. These articles are written from online videos

To customize a control, first look at the control it inherits from. If we inherit the view control, let's write a lot about listview functions. I think these things are very troublesome, and there is no need, because we can directly inherit the listview and add some things we need on the basis of listview.

1. Add header layout to listview

2. Hide header layout

3. Implement the drop-down refresh of listview (I)

To implement the drop-down refresh of the listview, you must monitor whether the listview slides to the top. Therefore, you need to implement the listener interface onscrolllistener of the listview and monitor the ontouch events of the listview. Judge the refresh condition according to the sliding condition.

First, we define a member variable to save the state of listview -- mState

Secondly, several static constants are defined to represent different states

Finally, the state of the mState is changed according to different slides

4. Implement the drop-down refresh of listview (II)

After the above process, you can pull down to handle events in different states. Another problem is refreshing, that is, loading new data. The operation of loading and refreshing must be in the UI thread, so there must be a callback interface in the listview to implement minaactivity and perform some operations.

Callback interface:

Call back interface:

Implementation of callback interface and interface method in mainactivity:

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