L中的RecyclerView onItemClick效果 [英] RecyclerView onItemClick effect in L

查看:55
本文介绍了L中的RecyclerView onItemClick效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许以前有人问过这个问题,但我找不到确切的答案.我已经在我的L测试应用程序中将RecyclerView小部件实现为列表,并且当您单击列表中的项目时,我想获得物质效果".我在ViewHolder的创建过程中实现了onClickListener并设置了属性

Maybe this question has been asked before, but I couldn't find a precise answer. I have implemented the RecyclerView widget as a list in my L test application and I want to get the 'material effect' when you click on an item form the list. I implemented an onClickListener in my ViewHolder creation and set the attribute

android:background="?android:attr/selectableItemBackground"

作为我的列表项布局(作为父项)的背景.

as a background to my list item layout (to the parent).

但是这些都不起作用.当我单击项目时,什么都不会发生.没有影响,没有影响,没有影响……请指出如果我在这里做错了什么……Thx

But none of this worked. When I click on the items NOTHING happens'. There is no effect, holo, material, none... Please point out if I am doing something wrong here... Thx

推荐答案

我犯了一个愚蠢的错误,没有提出

I made a silly mistake and did not put

android:clickable="true"
android:focusable="true"

到我的列表项布局.我认为L之前不需要这样做,但这没关系,因为在这种情况下这就是问题所在.

to my list item layout. I think this was not required pre L, but it doesn't matter because that was the problem in this case.

这篇关于L中的RecyclerView onItemClick效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆