Android 实现ListView item的左滑(右滑)监听事件 swipemenulistview

本文介绍了在Android中利用SwipeMenuListView库实现ListView项的左滑监听事件。首先引入库,然后替换原有ListView控件,创建布局文件和数据类。接着在MainActivity中设置控件属性并添加监听,通过Direction判断滑动方向,执行对应功能。
摘要由CSDN通过智能技术生成

这篇文章将会介绍我是如何学习item的左滑监听事件设置的,首先我们先添加依赖:
compile ‘com.baoyz.swipemenulistview:library:1.3.+’
可以看到,我们是借助大神所写的swipemenulistView这个空间来实现我们的左滑事件的。导入之后呢,我们就可以开始我们的项目了。

首先和往常写listView写好我们的布局文件,但是以前所有的listView控件就需要我们使用这一款新的控件代替了。
main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:swipe="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.administrator.learnlistviewmenu.MainActivity">

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >
    </com.baoyz.swipemenulistview.SwipeMenuListView>
</RelativeLayout>

接下来是我们的item布局文件:
list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
<TextView
    android:id="@+id/nameTextView"
    android:textSize="20sp"
    android:layout_width="match_parent"
    android:layout_height="40dp" />
    <TextView
        android:id="@+id/ageTextView"
        android:textSize="15sp"
        android:layout_width="match_parent"
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值