Skip to content

tsuryo/Swipeable-RecyclerView

Repository files navigation

Downloads Downloads

Swipeable-RecyclerView

Android library provides a simple to use Swipeable RecyclerView.

SwipeableRecyclerView SwipeableRecyclerView SwipeableRecyclerView

Prerequisites

Android 5.0+ API 21+

V1.3 what's new:

Corner radius support

app:leftCornerRadius="2dp"
app:rightCornerRadius="10dp"
app:cornerRadius="5dp"

Use cornerRadius to set radius globally for all sides. Use leftCornerRadius and rightCornerRadius if you need to customize each side independently.

RTL Support

app:supportRTL="false"
app:forceRTL="true"

supportRTL=true will switch sides to RTL if the device is using RTL language. forceRTL=true forces SwipeableRecyclerView to show RTL.

Features

  • Customizable texts, icons & backgrounds.
  • Customizable text size, text color.
  • One side/two sides swipe.
  • Really simple to use, implement swipe listener.
  • Set attributes using XML/Java.

Usage

Java

        SwipeableRecyclerView rv = findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.setAdapter(mAdapter);

        rv.setListener(new SwipeLeftRightCallback.Listener() {
            @Override
            public void onSwipedLeft(int position) {
                mList.remove(position);
                mAdapter.notifyDataSetChanged();
            }

            @Override
            public void onSwipedRight(int position) {
                mList.remove(position);
                mAdapter.notifyDataSetChanged();
            }
        });
	
	/*
         * Additional attributes:
         * */
        rv.setRightBg(R.color.blue);
        rv.setRightImage(R.drawable.ic_v);
        rv.setRightText("Right Text");

        rv.setLeftBg(R.color.red);
        rv.setLeftImage(R.drawable.ic_trash);
        rv.setLeftText("Left Text");

        rv.setTextSize(62);
        rv.setTextColor(R.color.white);

XML

    <!--all attributes-->
    <com.tsuryo.swipeablerv.SwipeableRecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:leftBgColor="@color/colorAccent"
        app:leftImage="@drawable/ic_remove"
        app:leftText="Delete"
        app:rightBgColor="@color/blue"
        app:rightImage="@drawable/ic_check"
        app:rightText="Read"
        app:textColor="@android:color/white"
        app:textSize="20sp" />
    <!--no images/icons-->
    <com.tsuryo.swipeablerv.SwipeableRecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:leftBgColor="@color/colorAccent"
        app:leftText="Delete"
        app:rightBgColor="@color/blue"
        app:rightText="Read"
        app:textColor="@android:color/white"
        app:textSize="20sp" />
    <!--no texts-->
    <com.tsuryo.swipeablerv.SwipeableRecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:leftBgColor="@color/colorAccent"
        app:leftImage="@drawable/ic_remove"
        app:rightBgColor="@color/blue"
        app:rightImage="@drawable/ic_check"
        app:textColor="@android:color/white"
        app:textSize="20sp" />
    <!--one side left-->
    <com.tsuryo.swipeablerv.SwipeableRecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:leftBgColor="@color/colorAccent"
        app:leftImage="@drawable/ic_trash"
        app:leftText="Delete"
        app:textColor="@android:color/white"
        app:textSize="20sp" />
    <!--one side right-->
    <com.tsuryo.swipeablerv.SwipeableRecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:rightBgColor="@color/colorAccent"
        app:rightImage="@drawable/ic_trash"
        app:rightText="Delete"
        app:textColor="@android:color/white"
        app:textSize="20sp" />
    <!--mixed-->
    <com.tsuryo.swipeablerv.SwipeableRecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:leftBgColor="@color/colorAccent"
        app:leftImage="@drawable/ic_trash"
        app:leftText="Delete"
        app:rightBgColor="@color/blue"
        app:rightImage="@drawable/ic_v"
        app:textColor="@android:color/white"
        app:textSize="20sp" />

Installing

Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency

dependencies {
        implementation 'com.github.tsuryo:Swipeable-RecyclerView:1.3'
	implementation 'androidx.recyclerview:recyclerview:+'
}