Implementation code of recyclerview drag and delete function in Android
No more nonsense. Let's show the effect.
This is the GridView master file implementation.
The code is not difficult to understand, but a lot of initialization things are set in the activity. Recyclerview initialization, setlayoutmanager, additemdecoration, sethasfixedsize, itemtouchhelper, addonitemtouchlistener, setadapter. The key code of drag effect is itemtouchhelper. Startdrag (viewholder). Everything else revolves around it.
Then look at the settings.
DataManager
Dividergriitemdecoration draws the sideline of the item
Recycleradapter adapter to establish connection with UI
Onrecycleritemclicklistener, click the event. We borrow gesture tool class gesturedetectorcompat to operate
RecyitemtouchhelperCallback
The following are the related settings of list
Similarly, listview is also an initialization setting.
DividerListItemDecoration
Source code download: http://download.csdn.net/download/loongago/9972876
summary
The above is the implementation code of recyclerview drag and side delete function in Android introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!