Android recyclerview pull-up loading and pull-down refresh (basic version)
Here, we use Google's native swiperefreshlayout to refresh, and use the scrolling event of recycleview to judge whether to load the last item. Here, we load more items using different items in the recycleview adapter.
This is the XML layout of the activity:
Next is the code in the corresponding activity:
Next is the XML file in the recycleview adapter:
This is the normal item layout. As for using cardview to make the item display better
This is a layout file that is actually pulled and loaded. It is displayed on the recycleview as different items:
Let's take a look at the writing of the recycleview adapter:
Finally, there are four different colors for the refresh control:
Required dependent libraries:
This is the end. More implementations of pull-down refresh and pull-up load are completed.
Here are three basic points of using recyclerview:
I:
II:
recyclerview.setItemAnimator(new DefaultItemAnimator()); The itemanimator will animate the changes to the view group based on the notifications received on the adapter. Basically, it automatically displays the add and remove item animation. This is not a simple class either, but we found that defaultitemanimator works well.
III:
For more details, please refer to: Android recyclerview uses full parsing of artistic controls
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.