yanzhenjie / SwipeRecyclerView

:melon: RecyclerView侧滑菜单,Item拖拽,滑动删除Item,自动加载更多,HeaderView,FooterView,Item分组黏贴。
https://github.com/yanzhenjie/SwipeRecyclerView
Apache License 2.0
5.65k stars 1.09k forks source link

菜单子项 设置 点击无效 #318

Open Boyka-SS opened 2 years ago

Boyka-SS commented 2 years ago

可不可以,菜单子项设置 成 不可点击 状态

luqiming666 commented 2 years ago

可以是可以的。参见我fork后修改的版本: https://github.com/luqiming666/SwipeRecyclerView

我增加了侧滑菜单展开/收起的回调通知:OnItemMenuStateListener,然后在收到菜单展开通知时这么处理:


 public void onMenuState(RecyclerView.ViewHolder viewHolder, int menuState) {
                MainAdapter.ViewHolder vh = (MainAdapter.ViewHolder) viewHolder;
                if (menuState == OPEN) {
                    vh.setHiddenView(true);

                    // 尝试修改菜单项的状态
                    SwipeMenuLayout menuLayout = (SwipeMenuLayout) vh.itemView;
                    if (menuLayout.hasRightMenu()) {
                        SwipeMenuView rightMenuView = (SwipeMenuView) menuLayout.getChildAt(2);
                        View view1 = rightMenuView.getChildAt(0); // 第一个menu item
                        view1.setEnabled(false);
                    }

                    Toast.makeText(DefineActivity.this, "菜单已展开,位置:" + viewHolder.getAdapterPosition(), Toast.LENGTH_SHORT).show();
                } else {
                    vh.setHiddenView(false);
                    Toast.makeText(DefineActivity.this, "菜单已收起,位置:" + viewHolder.getAdapterPosition(), Toast.LENGTH_SHORT).show();
                }
            }