如何在Recyclerview中触发其他卡片视图元素,而不是单击?
我使用RecyClerview在适配器中有一种方法,我基本上显示了cardViews
的一些元素。
如何在其他元素上触发方法,
cardView.setOnClickListener {
// MY action on specific} cardView element
例如,当我单击第三个元素时,我通常会在其中使用,<我的操作>
发生在第二个元素中? 在CardView内部,我可以使用:
statusButtons.toggleVisibility(!statusButtons.isVisible)
但是只有在使用方法触发实际元素时,它才能
cardView.setOnClickListener { }
找到类似的东西 访问Recyclerview中的所有卡片视图,单击特定的卡片浏览量,
但它与我的案例并不直接相关,我需要在特定ID上采取措施
statusButtons.toggleVisibility(!statusButtons.isVisible) where I not have argument to change
I have a method in adapter using recyclerview I basically display some elements of cardViews
.
How to trigger method on other element where usually I use
cardView.setOnClickListener {
// MY action on specific} cardView element
for example when I click third element, <MY ACTION>
happens in second element?
Inside cardView I can i.e use:
statusButtons.toggleVisibility(!statusButtons.isVisible)
but it will only work when I trigger actual element using method
cardView.setOnClickListener { }
I have found something similiar
How to access all cardviews in a recyclerview, on item click of a particular cardview
but it is not directly related to my case, I need to make action on specific ID like
statusButtons.toggleVisibility(!statusButtons.isVisible) where I not have argument to change
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
recyclerview.findviewholderforlayoutposition(position)
函数在给定位置获取view> view> view holder
,并从活动/fragment上调用该视图持有人。该函数返回
null
如果没有view> view holder
在给定位置
编辑:如果您需要
item.id.id:
在选择视图持有人的活动中,您也可以从lambda传递该项目。您可以根据需要从适配器发送到活动的任何信息来更新
oncardClick
lambda。另外,如果要将ID发送到操作
函数,也可以做到这一点。You can use the
RecyclerView.findViewHolderForLayoutPosition(position)
function to get theViewHolder
at given position and call functions on that ViewHolder from the activity/fragment.The function returns
null
if noViewHolder
exists at givenposition
Edit: If you need
item.id
in the activity for choosing the ViewHolder, you can pass the item as well from the lambda.You can update the
onCardClick
lambda depending upon whatever info you need to send from adapter to activity. Also, if you want to send the id to theoperateOnCard
function, you can also do that.解决方案:
在适配器中
Solution:
in Adapter