Detailed explanation of Android pull-down refresh and GridView usage

GridView is a control similar to listview, but GridView can use multiple columns to render content, and listview is in behavior units, so its usage is similar. For the main layout file, a ProgressBar is added because the drop-down refresh is required. The numcolumns property of GridView refers to the number of columns in each row

The layout file of each item. Here is a simple picture with a paragraph of text

Main activity Code:

Resolution: in the oncreate method, first obtain two components, then set the progressbar to hidden, display it when it is pulled down, and hide it after refreshing. Then set the data source for the GridView. For convenience, use simpleadapter, and then set ontouchlistener for the GridView. In the ontouch method, the touch event is handed over to our custom gesturedetector object for processing. In the onfling method of gesturedetector, the pull-down event is processed. In it, judge whether the drop-down and the GridView are at the top. If yes, Display the progressbar control and open a thread to handle the refresh. The simulation here will sleep for 2000 milliseconds. Finally, a message is returned to the handler with the message object, and the handler updates the GridView in the main thread.

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