Skip to content

Library for adding buttons on swipe gestures for android recycler views.

Notifications You must be signed in to change notification settings

hubercode/RecyclerViewSwiper

Repository files navigation

RecyclerViewSwiper

Library for adding buttons on swipe gestures for android recycler views.

Add the library to your project:

gradle:

Add it in your root build.gradle at the end of repositories:

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

Add the dependency to your app build.gradle

dependencies {
  implementation 'com.github.michaelhuber88:RecyclerViewSwiper:1.0'
}  

maven:

Add the JitPack repository to your build file

<repositories>
  <repository>
	  <id>jitpack.io</id>
	  <url>https://jitpack.io</url>
	</repository>
</repositories>

Add the dependency:

<dependency>
  <groupId>com.github.michaelhuber88</groupId>
  <artifactId>RecyclerViewSwiper</artifactId>
  <version>1.0</version>
</dependency>

How to use it:

RecyclerViewSwiper swiper = new RecyclerViewSwiper(this, this.recyclerView) {
    @Override
    public void initSwipeButtonRight(RecyclerView.ViewHolder viewHolder, List<SwipeButton> swipeButtons) {

        // DELETE

        swipeButtons.add(new SwipeButton(MainActivity.this, "DELETE", Color.RED, new SwipeButtonClickListener() {
            @Override
            public void onClick(int position) {
                items.remove(position);
                adapter.notifyDataSetChanged();
            }
        }));

        // COPY

        swipeButtons.add(new SwipeButton(MainActivity.this, "COPY", Color.BLACK, new SwipeButtonClickListener() {
            @Override
            public void onClick(int position) {
                items.add(items.get(position));
                adapter.notifyDataSetChanged();
                Toast.makeText(MainActivity.this, items.get(position) + " added", Toast.LENGTH_SHORT).show();
            }
        }));
    }

    @Override
    public void initSwipeButtonLeft(RecyclerView.ViewHolder viewHolder, List<SwipeButton> swipeButtons) {

        // INFO

        swipeButtons.add(new SwipeButton(MainActivity.this, "INFO", Color.BLUE, new SwipeButtonClickListener() {
            @Override
            public void onClick(int position) {
                Toast.makeText(MainActivity.this, items.get(position), Toast.LENGTH_SHORT).show();
                adapter.notifyDataSetChanged();
            }
        }));
    }
};
swiper.setButtonWidth(200);

About

Library for adding buttons on swipe gestures for android recycler views.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages