kaushal
kaushal

Reputation: 11

Issue: when i scroll child recycler view then activity's onRefresh method get invoked

I have a activity and my activity implemented SwipeRefreshLayout.OnRefreshListener.In my activity there is a nested recycler view.and i implemented onInterceptTouchEvent to child recycler view.so problem is when i scroll child recycler view then activity's onRefresh() method is called.this onRefresh() is for SwipeRefreshLayout.OnRefreshListener.

i added scrollTouchListener to childRecyclerView.please refer below code for your reference.

`val scrollTouchListener: RecyclerView.OnItemTouchListener = object :
 RecyclerView.OnItemTouchListener {
            override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
                when (e.action) {
                    MotionEvent.ACTION_UP -> rv.parent.requestDisallowInterceptTouchEvent(true)
                    MotionEvent.ACTION_DOWN -> rv.parent.requestDisallowInterceptTouchEvent(true)
                    MotionEvent.ACTION_MOVE -> rv.parent.requestDisallowInterceptTouchEvent(true)
                }
                return false
            }

            override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {
            }

            override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
            }
        }
        mBinding.childRecyclerView.addOnItemTouchListener(scrollTouchListener)`

Upvotes: 1

Views: 33

Answers (0)

Related Questions