禁用整个RecyclerView的点击 [英] Disable clicks on entire RecyclerView
问题描述
我想在整个项目中单击禁用整个 RecyclerView
,并在假定500毫秒后再次启用它.
I want to disable clicks on the entire RecyclerView
once an item of it is clicked and enable it back again after suppose 500 milis.
这个想法只是防止对RecyclerView项目中的项目的多次快速点击.例如,某人可能会快速点击3个项目,而所有这些项目都会被触发.
The idea is just to prevent multiple rapid clicks on the items of the RecyclerView items. For example, some one may quickly tap on 3 items and all of them will get triggered.
我尝试了 setEnabled(false)
和 setClickable(false)
,但它们都不能单独使用或一起使用.
I have tried setEnabled(false)
and setClickable(false)
but both of them doesn't work alone or when used together.
推荐答案
也许您必须禁用RecyclerView的所有子级.您可以这样做:
May be you have to disable all the children of the RecyclerView. You can do it like this:
private static void setViewAndChildrenEnabled(View view, boolean enabled) {
view.setEnabled(enabled);
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
setViewAndChildrenDisabled(child, enabled);
}
}
}
其中参数 view
是您的RecyclerView.
Where parameter view
is your RecyclerView.
这篇关于禁用整个RecyclerView的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!