RecycleView實現側滑刪除item
對於列表空間的側滑操作,網上有很多開源的空間可以使用,Google在它的新控件RecycleView中增加了側滑的API,完全遵循Material Design設計規範,下面看看效果演示:
下面看看介紹一下刷新控制類: ItemTouchHelper。
顧名思義,這個類就是來幫助我們對於item執行更多的操作。下面看看具體操作:
我們實例化這個類的時候需要傳入對應的會掉接口:
/** * Creates an ItemTouchHelper that will work with the given Callback. * <p> * You can attach ItemTouchHelper to a RecyclerView via * [email protected]
看源碼會發現這個接口是個抽象類,我們看看ItemTouchHelper中寫了一個抽象類繼承與該抽象類:
/** * Creates a Callback for the given drag and swipe allowance. These values serve as * defaults * and if you want to customize behavior per ViewHolder, you can override * [email protected]