# ItemTouchHelper

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#nestedclasses)\|[Constants](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#constants)\|[Ctors](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#)  

# ItemTouchHelper

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


class
ItemTouchHelper
`  
`


``

extends `[RecyclerView.ItemDecoration](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration)`


``


implements

`[RecyclerView.OnChildAttachStateChangeListener](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnChildAttachStateChangeListener)`


`

|---|---|--------------------------------------------------|
| java.lang.Object                                       |||
| ↳ | [android.support.v7.widget.RecyclerView.ItemDecoration](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration) ||
|   | ↳ | android.support.v7.widget.helper.ItemTouchHelper |

<br />

*** ** * ** ***

This is a utility class to add swipe to dismiss and drag \& drop support to RecyclerView.

It works with a RecyclerView and a Callback class, which configures what type of interactions are enabled and also receives events when user performs these actions.

Depending on which functionality you support, you should override[onMove(RecyclerView, ViewHolder, ViewHolder)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback#onMove(android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.ViewHolder, android.support.v7.widget.RecyclerView.ViewHolder))and / or[onSwiped(ViewHolder, int)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback#onSwiped(android.support.v7.widget.RecyclerView.ViewHolder, int)).

This class is designed to work with any LayoutManager but for certain situations, it can be optimized for your custom LayoutManager by extending methods in the[ItemTouchHelper.Callback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback)class or implementing[ItemTouchHelper.ViewDropHandler](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.ViewDropHandler)interface in your LayoutManager.

By default, ItemTouchHelper moves the items' translateX/Y properties to reposition them. You can customize these behaviors by overriding[onChildDraw(Canvas, RecyclerView, ViewHolder, float, float, int, boolean)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback#onChildDraw(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.ViewHolder, float, float, int, boolean))or[onChildDrawOver(Canvas, RecyclerView, ViewHolder, float, float, int, boolean)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback#onChildDrawOver(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.ViewHolder, float, float, int, boolean)).

<br />

Most of the time you only need to override`onChildDraw`.

<br />

## Summary

|                                                                                                                                                                    ### Nested classes                                                                                                                                                                    ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class`     | [ItemTouchHelper.Callback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback) This class is the contract between ItemTouchHelper and your application.                                                                                                                                     |
| ` class`     | [ItemTouchHelper.SimpleCallback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.SimpleCallback) A simple wrapper to the default Callback which you can construct with drag and swipe directions and this class will handle the flag callbacks.                                                   |
| ` interface` | [ItemTouchHelper.ViewDropHandler](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.ViewDropHandler) An interface which can be implemented by LayoutManager for better integration with[ItemTouchHelper](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper). |

|                                                                                                                             ### Constants                                                                                                                              ||
|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [ACTION_STATE_DRAG](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#ACTION_STATE_DRAG) A View is currently being dragged.                                                                                              |
| `int` | [ACTION_STATE_IDLE](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#ACTION_STATE_IDLE) ItemTouchHelper is in idle state.                                                                                               |
| `int` | [ACTION_STATE_SWIPE](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#ACTION_STATE_SWIPE) A View is currently being swiped.                                                                                             |
| `int` | [ANIMATION_TYPE_DRAG](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#ANIMATION_TYPE_DRAG) Animation type for views that were dragged and now will animate to their final position.                                    |
| `int` | [ANIMATION_TYPE_SWIPE_CANCEL](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#ANIMATION_TYPE_SWIPE_CANCEL) Animation type for views which are not completely swiped thus will animate back to their original position. |
| `int` | [ANIMATION_TYPE_SWIPE_SUCCESS](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#ANIMATION_TYPE_SWIPE_SUCCESS) Animation type for views which are swiped successfully.                                                   |
| `int` | [DOWN](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#DOWN) Down direction, used for swipe \& drag control.                                                                                                           |
| `int` | [END](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#END) Horizontal end direction.                                                                                                                                   |
| `int` | [LEFT](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#LEFT) Left direction, used for swipe \& drag control.                                                                                                           |
| `int` | [RIGHT](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#RIGHT) Right direction, used for swipe \& drag control.                                                                                                        |
| `int` | [START](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#START) Horizontal start direction.                                                                                                                             |
| `int` | [UP](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#UP) Up direction, used for swipe \& drag control.                                                                                                                 |

|                                                                                                                                                                                           ### Public constructors                                                                                                                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[ItemTouchHelper](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper.Callback))`(`[ItemTouchHelper.Callback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback)` callback) ` Creates an ItemTouchHelper that will work with the given Callback. |

|                                                                                                                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                                                                                                                  ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[attachToRecyclerView](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#attachToRecyclerView(android.support.v7.widget.RecyclerView))`(`[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` recyclerView) ` Attaches the ItemTouchHelper to the provided RecyclerView.                                                                                                                                                                                                                                                                                                                                              |
| ` void` | ` `[getItemOffsets](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#getItemOffsets(android.graphics.Rect, android.view.View, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))`(`[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` outRect, `[View](https://developer.android.com/reference/android/view/View.html)` view, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent, `[RecyclerView.State](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.State)` state) ` Retrieve any offsets for the given item. |
| ` void` | ` `[onChildViewAttachedToWindow](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#onChildViewAttachedToWindow(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` view) ` Called when a view is attached to the RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void` | ` `[onChildViewDetachedFromWindow](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#onChildViewDetachedFromWindow(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` view) ` Called when a view is detached from RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                          |
| ` void` | ` `[onDraw](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#onDraw(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)` c, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent, `[RecyclerView.State](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.State)` state) ` Draw any appropriate decorations into the Canvas supplied to the RecyclerView.                                                                             |
| ` void` | ` `[onDrawOver](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#onDrawOver(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)` c, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent, `[RecyclerView.State](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.State)` state) ` Draw any appropriate decorations into the Canvas supplied to the RecyclerView.                                                                     |
| ` void` | ` `[startDrag](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#startDrag(android.support.v7.widget.RecyclerView.ViewHolder))`(`[RecyclerView.ViewHolder](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ViewHolder)` viewHolder) ` Starts dragging the provided ViewHolder.                                                                                                                                                                                                                                                                                                                                                       |
| ` void` | ` `[startSwipe](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#startSwipe(android.support.v7.widget.RecyclerView.ViewHolder))`(`[RecyclerView.ViewHolder](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ViewHolder)` viewHolder) ` Starts swiping the provided ViewHolder.                                                                                                                                                                                                                                                                                                                                                      |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#)From class` `[android.support.v7.widget.RecyclerView.ItemDecoration](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration)` ` |---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` void` | ` `[getItemOffsets](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect, int, android.support.v7.widget.RecyclerView))`(`[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` outRect, int itemPosition, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent) ` *This method was deprecated in API level 22.1.0. Use[getItemOffsets(Rect, View, RecyclerView, State)](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect, android.view.View, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))* | | ` void` | ` `[getItemOffsets](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect, android.view.View, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))`(`[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` outRect, `[View](https://developer.android.com/reference/android/view/View.html)` view, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent, `[RecyclerView.State](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.State)` state) ` Retrieve any offsets for the given item.                                                                | | ` void` | ` `[onDraw](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas, android.support.v7.widget.RecyclerView))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)` c, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent) ` *This method was deprecated in API level 22.1.0. Override[onDraw(Canvas, RecyclerView, RecyclerView.State)](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))*                                                           | | ` void` | ` `[onDraw](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)` c, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent, `[RecyclerView.State](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.State)` state) ` Draw any appropriate decorations into the Canvas supplied to the RecyclerView.                                                                                                                                            | | ` void` | ` `[onDrawOver](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)` c, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent, `[RecyclerView.State](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.State)` state) ` Draw any appropriate decorations into the Canvas supplied to the RecyclerView.                                                                                                                                    | | ` void` | ` `[onDrawOver](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas, android.support.v7.widget.RecyclerView))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)` c, `[RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView)` parent) ` *This method was deprecated in API level 22.1.0. Override[onDrawOver(Canvas, RecyclerView, RecyclerView.State)](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas, android.support.v7.widget.RecyclerView, android.support.v7.widget.RecyclerView.State))*                                           | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#)From interface` `[android.support.v7.widget.RecyclerView.OnChildAttachStateChangeListener](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnChildAttachStateChangeListener)` ` |------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[onChildViewAttachedToWindow](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnChildAttachStateChangeListener#onChildViewAttachedToWindow(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` view) ` Called when a view is attached to the RecyclerView.   | | ` abstract void` | ` `[onChildViewDetachedFromWindow](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnChildAttachStateChangeListener#onChildViewDetachedFromWindow(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` view) ` Called when a view is detached from RecyclerView. | ||

## Constants

### ACTION_STATE_DRAG

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int ACTION_STATE_DRAG
```

A View is currently being dragged.

<br />

Constant Value: 2 (0x00000002)  

### ACTION_STATE_IDLE

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int ACTION_STATE_IDLE
```

ItemTouchHelper is in idle state. At this state, either there is no related motion event by the user or latest motion events have not yet triggered a swipe or drag.

<br />

Constant Value: 0 (0x00000000)  

### ACTION_STATE_SWIPE

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int ACTION_STATE_SWIPE
```

A View is currently being swiped.

<br />

Constant Value: 1 (0x00000001)  

### ANIMATION_TYPE_DRAG

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int ANIMATION_TYPE_DRAG
```

Animation type for views that were dragged and now will animate to their final position.

<br />

Constant Value: 8 (0x00000008)  

### ANIMATION_TYPE_SWIPE_CANCEL

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int ANIMATION_TYPE_SWIPE_CANCEL
```

Animation type for views which are not completely swiped thus will animate back to their original position.

<br />

Constant Value: 4 (0x00000004)  

### ANIMATION_TYPE_SWIPE_SUCCESS

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int ANIMATION_TYPE_SWIPE_SUCCESS
```

Animation type for views which are swiped successfully.

<br />

Constant Value: 2 (0x00000002)  

### DOWN

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int DOWN
```

Down direction, used for swipe \& drag control.

<br />

Constant Value: 2 (0x00000002)  

### END

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int END
```

Horizontal end direction. Resolved to LEFT or RIGHT depending on RecyclerView's layout direction. Used for swipe \& drag control.

<br />

Constant Value: 32 (0x00000020)  

### LEFT

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int LEFT
```

Left direction, used for swipe \& drag control.

<br />

Constant Value: 4 (0x00000004)  

### RIGHT

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int RIGHT
```

Right direction, used for swipe \& drag control.

<br />

Constant Value: 8 (0x00000008)  

### START

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int START
```

Horizontal start direction. Resolved to LEFT or RIGHT depending on RecyclerView's layout direction. Used for swipe \& drag control.

<br />

Constant Value: 16 (0x00000010)  

### UP

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int UP
```

Up direction, used for swipe \& drag control.

<br />

Constant Value: 1 (0x00000001)

## Public constructors

### ItemTouchHelper

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
ItemTouchHelper (ItemTouchHelper.Callback callback)
```

Creates an ItemTouchHelper that will work with the given Callback.

You can attach ItemTouchHelper to a RecyclerView via[attachToRecyclerView(RecyclerView)](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper#attachToRecyclerView(android.support.v7.widget.RecyclerView)). Upon attaching, it will add an item decoration, an onItemTouchListener and a Child attach / detach listener to the RecyclerView.

<br />

|                                                  Parameters                                                   ||
|------------|---------------------------------------------------------------------------------------------------|
| `callback` | `ItemTouchHelper.Callback`: The Callback which controls the behavior of this touch helper. <br /> |

## Public methods

### attachToRecyclerView

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void attachToRecyclerView (RecyclerView recyclerView)
```

Attaches the ItemTouchHelper to the provided RecyclerView. If TouchHelper is already attached to a RecyclerView, it will first detach from the previous one. You can call this method with`null`to detach it from the current RecyclerView.

<br />

|                                                                                     Parameters                                                                                     ||
|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `recyclerView` | `RecyclerView`: The RecyclerView instance to which you want to add this helper or`null`if you want to remove ItemTouchHelper from the current RecyclerView. <br /> |

### getItemOffsets

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void getItemOffsets (Rect outRect, 
                View view, 
                RecyclerView parent, 
                RecyclerView.State state)
```

Retrieve any offsets for the given item. Each field of`outRect`specifies the number of pixels that the item view should be inset by, similar to padding or margin. The default implementation sets the bounds of outRect to 0 and returns.

If this ItemDecoration does not affect the positioning of item views, it should set all four fields of`outRect`(left, top, right, bottom) to zero before returning.

If you need to access Adapter for additional data, you can call[getChildAdapterPosition(View)](https://developer.android.com/reference/android/support/v7/widget/RecyclerView#getChildAdapterPosition(android.view.View))to get the adapter position of the View.

<br />

|                                    Parameters                                    ||
|-----------|-----------------------------------------------------------------------|
| `outRect` | `Rect`: Rect to receive the output. <br />                            |
| `view`    | `View`: The child view to decorate <br />                             |
| `parent`  | `RecyclerView`: RecyclerView this ItemDecoration is decorating <br /> |
| `state`   | `RecyclerView.State`: The current state of RecyclerView. <br />       |

### onChildViewAttachedToWindow

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onChildViewAttachedToWindow (View view)
```

Called when a view is attached to the RecyclerView.

<br />

|                              Parameters                               ||
|--------|---------------------------------------------------------------|
| `view` | `View`: The View which is attached to the RecyclerView <br /> |

### onChildViewDetachedFromWindow

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onChildViewDetachedFromWindow (View view)
```

Called when a view is detached from RecyclerView.

<br />

|                                  Parameters                                   ||
|--------|-----------------------------------------------------------------------|
| `view` | `View`: The View which is being detached from the RecyclerView <br /> |

### onDraw

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onDraw (Canvas c, 
                RecyclerView parent, 
                RecyclerView.State state)
```

Draw any appropriate decorations into the Canvas supplied to the RecyclerView. Any content drawn by this method will be drawn before the item views are drawn, and will thus appear underneath the views.

<br />

|                                    Parameters                                     ||
|----------|-------------------------------------------------------------------------|
| `c`      | `Canvas`: Canvas to draw into <br />                                    |
| `parent` | `RecyclerView`: RecyclerView this ItemDecoration is drawing into <br /> |
| `state`  | `RecyclerView.State`: The current state of RecyclerView <br />          |

### onDrawOver

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onDrawOver (Canvas c, 
                RecyclerView parent, 
                RecyclerView.State state)
```

Draw any appropriate decorations into the Canvas supplied to the RecyclerView. Any content drawn by this method will be drawn after the item views are drawn and will thus appear over the views.

<br />

|                                    Parameters                                     ||
|----------|-------------------------------------------------------------------------|
| `c`      | `Canvas`: Canvas to draw into <br />                                    |
| `parent` | `RecyclerView`: RecyclerView this ItemDecoration is drawing into <br /> |
| `state`  | `RecyclerView.State`: The current state of RecyclerView. <br />         |

### startDrag

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void startDrag (RecyclerView.ViewHolder viewHolder)
```

Starts dragging the provided ViewHolder. By default, ItemTouchHelper starts a drag when a View is long pressed. You can disable that behavior by overriding[isLongPressDragEnabled()](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback#isLongPressDragEnabled()).

For this method to work:

- The provided ViewHolder must be a child of the RecyclerView to which this ItemTouchHelper is attached.
- [ItemTouchHelper.Callback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback)must have dragging enabled.
- There must be a previous touch event that was reported to the ItemTouchHelper through RecyclerView's ItemTouchListener mechanism. As long as no other ItemTouchListener grabs previous events, this should work as expected.

For example, if you would like to let your user to be able to drag an Item by touching one of its descendants, you may implement it as follows:  

```
     viewHolder.dragButton.setOnTouchListener(new View.OnTouchListener() {
         public boolean onTouch(View v, MotionEvent event) {
             if (MotionEvent.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                 mItemTouchHelper.startDrag(viewHolder);
             }
             return false;
         }
     });
 
```

<br />

<br />

|                                                          Parameters                                                          ||
|--------------|----------------------------------------------------------------------------------------------------------------|
| `viewHolder` | `RecyclerView.ViewHolder`: The ViewHolder to start dragging. It must be a direct child of RecyclerView. <br /> |

**See also:**

- [isItemViewSwipeEnabled()](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback#isItemViewSwipeEnabled())  

### startSwipe

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void startSwipe (RecyclerView.ViewHolder viewHolder)
```

Starts swiping the provided ViewHolder. By default, ItemTouchHelper starts swiping a View when user swipes their finger (or mouse pointer) over the View. You can disable this behavior by overriding[ItemTouchHelper.Callback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback)

For this method to work:

- The provided ViewHolder must be a child of the RecyclerView to which this ItemTouchHelper is attached.
- [ItemTouchHelper.Callback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback)must have swiping enabled.
- There must be a previous touch event that was reported to the ItemTouchHelper through RecyclerView's ItemTouchListener mechanism. As long as no other ItemTouchListener grabs previous events, this should work as expected.

For example, if you would like to let your user to be able to swipe an Item by touching one of its descendants, you may implement it as follows:  

```
     viewHolder.dragButton.setOnTouchListener(new View.OnTouchListener() {
         public boolean onTouch(View v, MotionEvent event) {
             if (MotionEvent.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                 mItemTouchHelper.startSwipe(viewHolder);
             }
             return false;
         }
     });
 
```

<br />

<br />

|                                                         Parameters                                                          ||
|--------------|---------------------------------------------------------------------------------------------------------------|
| `viewHolder` | `RecyclerView.ViewHolder`: The ViewHolder to start swiping. It must be a direct child of RecyclerView. <br /> |

-

  ## Interfaces

  - [ItemTouchHelper.ViewDropHandler](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.ViewDropHandler)
  - [ItemTouchUIUtil](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchUIUtil)
-

  ## Classes

  - [ItemTouchHelper](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper)
  - [ItemTouchHelper.Callback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback)
  - [ItemTouchHelper.SimpleCallback](https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.SimpleCallback)