RecyclerView calling setTextColor for one Item affects other Items

Viewed 45

Not sure if anyone had this happen but when I change something for an item (childView) in a RecycleView the same gets applied for the item 12 positions below/above. Does anyone have any insight on this?

    override fun onInterceptTouchEvent(view: RecyclerView, e: MotionEvent): Boolean {
        val childView = view.findChildViewUnder(e.x, e.y)

        if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
            val letterOfDay = childView.findViewById<TextView>(R.id.letterOfDay)
            val dayOfMonth = childView.findViewById<TextView>(R.id.dayOfMonth)
            val dayOfMonthActive = childView.findViewById<ImageView>(R.id.button)

            dayOfMonthActive.visibility = View.VISIBLE
            letterOfDay.setTextColor(Color.parseColor("#ffffff"))
            dayOfMonth.setTextColor(Color.parseColor("#001419"))

            mListener.onItemClick(childView, view.getChildAdapterPosition(childView))
            return true
        }
        return false
    }

So, this code sets text color for 2 different items 12 positions apart. It's called once, I'm thinking it's something to do with RecyclerView.

Edit: when I call

recyclerView.findChildViewUnder(1f,1f)

or

view.findChildViewUnder(e.x, e.y)

it doesn't pinpoint to a single childview but instead aims for 2 in my case, I am not sure why it does this though.

1 Answers

In the touch event, you are setting the color for views that are represented in a view holder. Are you resetting the color when the view holder is reused and rebound? If not, then you will what appears to be action in one view holder just magically appear in another distant view holder.

Related