What is the recommended way to setup multiple clic...
# android
j
What is the recommended way to setup multiple click listeners for buttons within a single RecyclerView row?
g
This is not related to Kotlin, please check channel's description
👍 1
☝️ 1
j
You can pass them through the recyclerview constructor using lambda parameters and have your activity or fragment handle the click event
👍 1
j
Thanks, I'll try that route. Also, sorry for going off topic.
s
multiple click listeners for the same button? or one click listener for each button in a view holder? The best appraoch imo is to use an interface. define an interface which contains all methods which act as click listeners without. implement the interface in your activity or fragment and implement each of the methods in your activity or fragment. Pass in the activity or fragment to the contractor of your adapter.
a
send an id (like when u send a position)to distinguished the buttons
j
Yeah, so basically each item row would have several buttons, three currently, that do different things. One would be to delete that item, one to copy, and another to make a textview on that row visible, like a password field.
a
Check out this article: https://medium.com/androiddevelopers/for-my-next-trick-i-will-write-about-onclick-45e0a6881c8a might help you understand how you should approach it. Same concept applies in case you have multiple views which require click handling.
130 Views