一个超好用的侧拉删除框架

博客介绍了布局文件、适配器(adapter)以及activity调用相关内容,涉及信息技术中前端或移动开发里的页面布局与交互逻辑部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

感谢大神,赐给我力量
implementation 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0'

布局文件如下: 

<com.mcxtzhang.swipemenulib.SwipeMenuLayout         
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="98px"
    android:clickable="true"
    app:ios="false"
    app:leftSwipe="true"
    app:swipeEnable="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_height="48dp">

        <TextView
            android:layout_width="wrap_content"
            android:text="正常布局内容"
            android:layout_height="wrap_content" />
    </LinearLayout>


    <Button
        android:id="@+id/btnDelete"
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:background="#ff4a57"
        android:text="删除"
        android:textColor="@android:color/white"/>

</com.mcxtzhang.swipemenulib.SwipeMenuLayout>

adapter如下

 class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
        ViewHolder holder = null;

        private onSwipeListener mOnSwipeListener;

        public void setOnDelListener(onSwipeListener mOnDelListener) {
            this.mOnSwipeListener = mOnDelListener;
        }


        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(GoldMajorListActivity2.this).inflate(R.layout.item_gold2, parent, false);
            holder = new ViewHolder(view);
            holder.number = view.findViewById(R.id.tv_number);
            holder.btnDelete = view.findViewById(R.id.btnDelete);
            return holder;
        }

        @Override
        public void onBindViewHolder(final ViewHolder holder, final int position) {
            CandidateWishsBean candidateWishsBean = candidateWishs.get(position);
            holder.number.setText(1 + position + "");
            holder.btnDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (null != mOnSwipeListener) {
                        //且如果想让侧滑菜单同时关闭,需要同时调用 
                        //((SwipeMenuLayout) holder.itemView).quickClose();
                        mOnSwipeListener.onDel(holder.itemView, position);
                    }
                }
            });
        }

        @Override
        public int getItemCount() {
            return candidateWishs == null ? 0 : candidateWishs.size();
        }

        class ViewHolder extends RecyclerView.ViewHolder {
            TextView number;
            Button btnDelete;

            public ViewHolder(View itemView) {
                super(itemView);
            }
        }
    }

 activity调用

        adapter.setOnDelListener(new onSwipeListener() {
            @Override
            public void onDel(View view, int pos) {
                SwipeMenuLayout swipeMenuLayout = (SwipeMenuLayout) view;
                swipeMenuLayout.quickClose();
                Log.e("syw", "pos:" + pos);
            }
        });

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值