Answer the question
In order to leave comments, you need to log in
Implementing click listener in RecyclerView?
Good afternoon! Very often in the examples I see the click processing logic directly in the RecyclerView adapter, and in connection with this, the question arose - shouldn't the adapter and logic be separated? After all, it is possible to hang a listener on the view in the adapter, and write the processing in another class? However, I often see that the logic is written directly in the adapter. How common is this practice in real projects, are there any conventions or best practices in this regard?
Answer the question
In order to leave comments, you need to log in
Necessarily. We put RecyclerView.OnItemsTouchListener in it, override onInterceptTouchEvent () - if it is necessary to process for the incoming event - then we call the onTouchEvent () method of the previously created GestureDetector with the GestureListener implemented and installed, in which we process the touch we need. The only way.
In the ViewHolder heir to the view that is passed to the constructor, hang a listener (on the root one or not) in the simplest and most logical way.
I like to use EventBus for this, you can pass the interface through the constructor to anyone as you like and depending on the situation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question