A listening example of adding recycleview in Android to the bottom

We often use drop-down refresh in our daily development, and the best open-source drop-down refresh component evaluated on the Internet is of course Android ultra pull to refresh. This component can add drop-down refresh function to any control. Of course, it also includes recycleview.

Unfortunately, Android ultra pull to refresh only provides the function of pull-down refresh, but for list components, we often use the function of pull-up loading or sliding to the bottom for automatic loading in our daily development. Of course, at present, users prefer the function of sliding to the bottom for automatic loading. For example, in today's recycleview, we can only add more functions by sliding to the bottom.

Its implementation principle is that Shenma is very simple:

Recycleview has an abstract class onscrolllistener for sliding listening to receive rolling events. There are two implemented methods in this class

Tongduo source code comments can be learned

Onscrollstatechanged called when the scrolling state of the recyclerview changes.

Onscrolled is called when the layout is visible and the recycleview scrolls.

Then the idea is:

(1) In the onscrollstatechanged method, judge whether the current scrolling state is the state of stopping scrolling.

(2) The last visible position is then obtained according to the methods in the API.

(3) Judge that the number of items in the currently visible recycleview is greater than 0

(4) Determine whether the last visible position is greater than the total number of items minus one

(5) And the total number of items is greater than the visible items, so that it can be executed only when there is more than one interface.

When the requirements of the interface are met, we can execute our time-consuming logic through the interface callback and display the loaded dialog.

Because recyclerview can be flexibly converted into lists, tables, and waterfall flows through layoutmanager. Especially for waterfall flow, its last visible position is different, so we must obtain the corresponding last visible position according to its different layoutmanager states.

code:

We can get all the columns of the waterfall flow through the API, and find the lowest column through the following methods. Displays the loaded dialog below this column.

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