Android Library to provide swipe, click and other functionality to RecyclerView

Overview

RecyclerViewEnhanced

Android Library to provide swipe, click and other functionality to RecyclerView

Usage

Add this to your build.gradle file

dependencies {
  compile 'com.nikhilpanju.recyclerviewenhanced:recyclerviewenhanced:1.1.0'
}

Features

  • Supports API 14+ (Earlier APIs not tested
  • Supports any view for "Swipe Options"
  • Doesn't require any new adapters or new views. Works with any existing RecyclerViews.
  • Requires adding OnItemTouchListener to the RecyclerView
  • Supports clicking and swiping functionalities.
  • Supports disabling clicking and swiping for particular items/rows.
  • Supports independentViews in your items/rows (Read below for more information)
  • Supports fadeViews in your items/rows (Read below for more information)

Demo

Build the sample application to try RecyclerViewEnhanced alt text

Configuring

  • Create an instance of RecyclerTouchListener

    onTouchListener = new RecyclerTouchListener(this, mRecyclerView);

  • Set IndependentViews and FadeViews (If required)

    IndependentViews are views which can be clicked separately from the entire row. Their clicks have different functionality from row clicks. FadeViews are views which fade in and out as the rows are swiped closed and opened respectively.

    onTouchListener.setIndependentViews(R.id.rowButton)
                   .setViewsToFade(R.id.rowButton)               
    
  • Implement OnRowClickListener using setClickable()

    setClickable() will enable clicks for the recycler view items and the IndependentViews

    .setClickable(new RecyclerTouchListener.OnRowClickListener() {
              @Override
              public void onRowClicked(int position) {
                  // Do something
              }
    
              @Override
              public void onIndependentViewClicked(int independentViewID, int position) {
                  // Do something
              }
          })               
    
  • Enable Swipe Functionality

    Set the views for which you require a click listener and enable swiping by using setSwipeable()

    .setSwipeOptionViews(R.id.add, R.id.edit, R.id.change)
    .setSwipeable(R.id.rowFG, R.id.rowBG, new RecyclerTouchListener.OnSwipeOptionsClickListener() {
              @Override
              public void onSwipeOptionClicked(int viewID, int position) {
                  if (viewID == R.id.add) {
                      // Do something
                  } else if (viewID == R.id.edit) {
                      // Do something
                  } else if (viewID == R.id.change) {
                      // Do something
                  }
             }
         });
    
  • Adding the listener to the RecyclerView

    In onResume() add the listener:

    mRecyclerView.addOnItemTouchListener(onTouchListener);
    

    In onPause() remove the listener:

    mRecyclerView.removeOnItemTouchListener(onTouchListener);
    

Additional Functionality

  • Use onRowLongClickListener to receive long click events

    .setLongClickable(true, new RecyclerTouchListener.OnRowLongClickListener() {
                      @Override
                      public void onRowLongClicked(int position) {
                          ToastUtil.makeToast(getApplicationContext(), "Row " + (position + 1) + " long clicked!");
                      }
                  })
    
  • Use setUnSwipeableRows() to disable certain rows from swiping. Using this also displays an "difficult-to-slide" animation when trying to slide an unswipeable row.

  • Use setUnClickableRows() to disable click actions for certain rows. (Note: This also prevents the independentViews from being clicked).

  • openSwipeOptions() opens the swipe options for a specific row.

  • closeVisibleBG() closes any open options.

  • Implement OnSwipeListener to get onSwipeOptionsClosed() and onSwipeOptionsOpened() events.

Closing swipe options when clicked anywhere outside of the recyclerView:

  • Make your Activity implement RecyclerTouchListener.RecyclerTouchListenerHelper and store the touchListener
private OnActivityTouchListener touchListener;

@Override
public void setOnActivityTouchListener(OnActivityTouchListener listener) {
    this.touchListener = listener;
}
  • Override dispatchTouchEvent() of your Activity and pass the MotionEvent variable to the touchListener
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (touchListener != null) touchListener.getTouchCoordinates(ev);
        return super.dispatchTouchEvent(ev);
}

Author

License

Copyright 2016 Nikhil Panju

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

(http://www.apache.org/licenses/LICENSE-2.0)

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Comments
  • Ryan/ignored view types

    Ryan/ignored view types

    Many recycler views will have items of varying types. You may not want to have the same foreground/background and swiping behaviors for these views (as I found in my own project using this library).

    opened by ryansgot 6
  •  some problems

    some problems

    I found that when the screen turns off when the swiped becomes ineffective and Viewholder multiplexing effect occurs.

    test environment: Millet 3 system: 6.0.1

    opened by BelongsH 5
  • when I refresh the data of recyclerview,app crush;hope to get your help

    when I refresh the data of recyclerview,app crush;hope to get your help

    log belows: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getHeight()' on a null object reference at com.nikhilpanju.recyclerviewenhanced.RecyclerTouchListener.handleTouchEvent(RecyclerTouchListener.java:474) at com.nikhilpanju.recyclerviewenhanced.RecyclerTouchListener.onInterceptTouchEvent(RecyclerTouchListener.java:127) at android.support.v7.widget.RecyclerView.dispatchOnItemTouchIntercept(RecyclerView.java:2231) at android.support.v7.widget.RecyclerView.onInterceptTouchEvent(RecyclerView.java:2277) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1977) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2066) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2066) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2066) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2066) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2066) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2435) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2066) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2485) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1783) at android.app.Activity.dispatchTouchEvent(Activity.java:2835) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2444) at android.view.View.dispatchPointerEvent(View.java:8712) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4236) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4090) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3618) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3684) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3644) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3773) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3652) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3830) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3618) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3684) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3644) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3652) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3618) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5962) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5936) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5896) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6059) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:193) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:143) at android.os.Looper.loop(Looper.java:122) at android.app.ActivityThread.main(ActivityThread.java:5400) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1037) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

    opened by Reteyery 3
  • Api 28

    Api 28

    Hi. I have been using your library for half a year. But recently I switched to api 28 and I began to receive crashes with an error: "Attempt to invoke interface method 'boolean androidx.recyclerview.widget.RecyclerView$OnItemTouchListener.onInterceptTouchEvent(androidx.recyclerview.widget.RecyclerView, android.view.MotionEvent)' on a null object reference android.view.ViewGroup.dispatchTouchEvent". Can you help me?

    opened by svns 1
  • I get error when using swipe on dialogFragment

    I get error when using swipe on dialogFragment

    I use your swipe on activity or fragment it runs but when running on dialogFragment it can't swipe, have you ever had the same situation as me. thanks

    opened by nguyen-khang-w 0
  • onTouchListner.openSwipeOptions() not working

    onTouchListner.openSwipeOptions() not working

    when I call the onTouchListner.openSwipeOptions() method, it doesn't openSwipeOptions for the correct row if the recycler view has been scrolled past the first few visible items.

    here is my code:

    onTouchListener.setClickable(new RecyclerTouchListener.OnRowClickListener() {
          @Override
          public void onRowClicked(int position) {
            onTouchListener.openSwipeOptions(position);
          }
    
          @Override
          public void onIndependentViewClicked(int independentViewID, int position) {
    
          }
    });
    
    opened by abdalmoniem 1
  • Issue when getting data from Firebase

    Issue when getting data from Firebase

    While loading data from firebase, the view doesn't respond, i.e. I cannot scroll it, and cannot swipe it. On further inspection, I am getting this kind of error:

    E/ViewRootImpl: mView does not exist, so discard the remaining points. java.lang.NullPointerException: Attempt to invoke interface method 'boolean androidx.recyclerview.widget.RecyclerView$OnItemTouchListener.onInterceptTouchEvent(androidx.recyclerview.widget.RecyclerView, android.view.MotionEvent)' on a null object reference
    I/Surface: opservice is null false
    

    I even tried to attach onTouchListener, when the list is loaded. But still not working.

    opened by ssindher11 1
Releases(1.1)
Owner
Nikhil Panju
Nikhil Panju
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.

UltimateRecyclerView Master branch: Dev branch: Project website:https://github.com/cymcsg/UltimateRecyclerView Description UltimateRecyclerView is a R

MarshalChen 7.2k Jan 2, 2023
TikTok-RecyclerView - This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoPlayer2.

TikTok-RecyclerView Demo About This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoP

Baljeet Singh 19 Dec 28, 2022
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
Pagination-RecyclerView - Simple and easy way to Paginating a RecyclerView

Pagination-RecyclerView Simple and easy way to Paginating a RecyclerView Android

Rakshit Nawani 0 Jan 3, 2022
ANDROID. ChipsLayoutManager (SpanLayoutManager, FlowLayoutManager). A custom layout manager for RecyclerView which mimicric TextView span behaviour, flow layouts behaviour with support of amazing recyclerView features

ChipsLayoutManager This is ChipsLayoutManager - custom Recycler View's LayoutManager which moves item to the next line when no space left on the curre

Oleg Beloy 3.2k Dec 25, 2022
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Jack and phantom 504 Dec 25, 2022
RecyclerView : SleepQualityTracker with RecyclerView app

RecyclerView - SleepQualityTracker with RecyclerView app SleepQualityTracker with RecyclerView This app builds on the SleepQualityTracker developed pr

Kevin 2 May 14, 2022
Android library for RecyclerView to manage order of items and multiple view types.

recyclerview-binder Android Library for RecyclerView to manage order of items and multiple view types. Features Insert any items to wherever you want

Satoru Fujiwara 185 Nov 15, 2022
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022
Elegant design and convenient to use RecyclerView adapter library based on Kotlin DSL.

xAdapter: Kotlin DSL 风格的 Adapter 封装 1、简介 该项目是 KotlinDSL 风格的 Adapter 框架封装,用来简化 Adapter 调用,思想是采用工厂和构建者方式获取 Adapter 避免代码中定义大量的 Adapter 类。该项目在 BRVAH 的 Ada

ShouHeng 17 Oct 9, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 8, 2023
Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

RecyclerView-FlexibleDivider Android library providing simple way to control divider items of RecyclerView Release Note [Release Note] (https://github

Yoshihito Ikeda 2.4k Dec 18, 2022
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Yoshihito Ikeda 414 Nov 21, 2022
Epoxy is an Android library for building complex screens in a RecyclerView

Epoxy Epoxy is an Android library for building complex screens in a RecyclerView. Models are automatically generated from custom views or databinding

Airbnb 8.1k Dec 29, 2022
An android library for quick setup of RecyclerView

SmartRecyclerView for Android An android library to quickly setup RecyclerView(List) with SwipeRefreshLayout Support, written entirely in Kotlin. Supp

Kunal Pasricha 16 Oct 18, 2022