简体   繁体   English

如何禁用回收者视图项目选择

[英]How to disable recycler view item selection

movieListRecyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
                    @Override
                    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                        // true: consume touch event
                        // false: dispatch touch event
                        return false;
                    }
                });

but once disabled I am not able to enable it back ,is there any way to make it work like toggle which will enable and disable RecyclerView 但是一旦禁用,我将无法重新启用它,是否有任何方法可以使它像切换一样启用和禁用RecyclerView

also recyclerview.setEnabled(false) is not working recyclerview.setEnabled(false)不起作用

This will work: 这将起作用:

Use boolean variable and setting default value to false and change value on button click. 使用布尔变量并将默认值设置为false并在单击按钮时更改值。

boolean touch = false;

    movieListRecyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
                        @Override
                        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                            // true: consume touch event
                            // false: dispatch touch event
                            return touch;
                        }
                    });

and on your button click or whatever click change boolean value; 在您的按钮上单击或任何单击更改布尔值的按钮;

 onClick(){
 touch = !touch;
}

If you want to disable click on whole items of recyclerview then add below lines in parent view of row item . 如果要禁用,请单击recyclerview的整个项目,然后在行项目的父视图中添加以下行。

  android:clickable="false"
  android:focusable="false"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM