Android – process recyclerview onclicklistener in activity / fragment

Migrating from listview to recyclerview to handle "onItemClick" seems to be very painful

One of the two most common methods is to let the viewholder implement view. Onclicklistener and handle onclick there. Here is an example of this method

What is a good way to send this "onclick" from the project's viewholder to the fragment / activity hosting the recycleview and process it there?

thank you!

resolvent:

As you said, there are some methods, and the implementation depends on the design of the rest of the code. What do you want the logic and modulus of the object to be

>You can find onitemclicklistener to add to the whole holder here and if you only need to click the whole item, this is a good method. Note: if you plan to use it to implement swipe2dississ, it will make you feel pain due to touch events and multiple toucheventlisteners > let your clip implement onclicklistener and pass it to the adapter, Then pass it to the holder to get onclick the viewpoint event in the holder you want, and then create a switch case in the fragment that handles it

IMO: the best practice is to pass onclicklisteners, because it is easier to implement when you want to use the view in different classes and want to do different click processing

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>