yanzhenjie / SwipeRecyclerView

:melon: RecyclerView侧滑菜单,Item拖拽,滑动删除Item,自动加载更多,HeaderView,FooterView,Item分组黏贴。
https://github.com/yanzhenjie/SwipeRecyclerView
Apache License 2.0
5.64k stars 1.09k forks source link

setOnItemStateChangedListener没有工作 #276

Open Fover23 opened 5 years ago

Fover23 commented 5 years ago

外部容器我使用了SmartRefreshLayout。

是我使用的方式不对么?我想要一个滑动删除的功能,滑动按钮能够展示,并且接受点击事件,不过就是setOnItemStateChangedListener没有callback,我需要在滑动的时候改变一下背景。

代码片段

washer_list.setSwipeMenuCreator { leftMenu, rightMenu, position ->
            val delItem= SwipeMenuItem(activity)
            delItem.setBackgroundColor(Color.RED)
            delItem.setBackground(R.mipmap.ic_item_del)
            delItem.text = "删除"
            delItem.setTextColor(Color.WHITE)
            rightMenu?.addMenuItem(delItem)
        }

        washer_list.isSwipeItemMenuEnabled=true
        washer_list.isLongPressDragEnabled=true

        washer_list.setOnItemStateChangedListener { viewHolder, actionState ->
            loge("action state execute $actionState")
            when(actionState){
                OnItemStateChangedListener.ACTION_STATE_SWIPE->{
                    loge("action state swipe")
                }
            }
        }

        washer_list.setOnItemMoveListener(object :OnItemMoveListener{
            override fun onItemMove(
                srcHolder: RecyclerView.ViewHolder?,
                targetHolder: RecyclerView.ViewHolder?
            ): Boolean {
                loge("item move ")
                return true
            }

            override fun onItemDismiss(srcHolder: RecyclerView.ViewHolder?) {
                loge("item dismiss")

            }
        })

        washer_list.setOnItemMenuClickListener { menuBridge, adapterPosition ->
            menuBridge.closeMenu()
        }