ItemTouchHelper onSelectedChanged callback

21 views Asked by At

I am trying to change the color of the swiping item in a RecyclerView. The thing is the color changes when I swipe some item but doesn't get back the source color when the item is not in focus.

override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
    super.onSelectedChanged(viewHolder, actionState)
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        viewHolder?.itemView?.background =
            ResourcesCompat.getDrawable(resources, R.drawable.item_background_gradient, null)
    }
}
0

There are 0 answers