Has anyone using RecyclerView
found a way to set an onClickListener
to items in the RecyclerView
?
I thought of setting a listener to each of the layouts for each item but that seems a little too much hassle
I'm sure there is a way for the RecyclerView
to listen for the onClick
event but I can't quite figure it out.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Based on Jacob Tabak's answer (+1 for him), I was able to add onLongClick listener:
Then you can use it like this:
Kotlin implementation of nhaarman's answer :
RecyclerItemClickListener.java :
Here is a better and less tightly coupled way to implement an
OnClickListener
for aRecyclerView
.Snippet of usage:
RecyclerItemClickListener
implementation:I do it in this way, without undue classes, detectors etc. Simple code inside our adapter. Especially better solution for longClick than presented before.
Then inside fragment or activity, just hit:
}
Implementation of this:
Same can be done for long click