【问题标题】:Disable clicks on entire RecyclerView禁用对整个 RecyclerView 的点击
【发布时间】:2016-03-18 18:30:45
【问题描述】:

我想禁用对整个项目的点击 RecyclerView 一旦点击其中的一个项目并在假设 500 英里后再次启用它。

这个想法只是为了防止多次快速点击 RecyclerView 项目的项目。例如,有人可能会快速点击 3 个项目,所有项目都会被触发。

我尝试过setEnabled(false)setClickable(false),但它们都不能单独使用或一起使用。

【问题讨论】:

  • 能否分享一下在recyclerview中设置item click listener的代码。

标签: android listview view android-recyclerview


【解决方案1】:

可能您必须禁用 RecyclerView 的所有子项。 你可以这样做:

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。

【讨论】:

    【解决方案2】:

    使用 RxJava throttlefirst 操作符,非常简单。

    【讨论】:

      猜你喜欢
      • 2011-09-26
      • 2021-08-13
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-09
      相关资源
      最近更新 更多