# RecyclerView swipe

**URL:** <https://forums.kodeco.com/t/recyclerview-swipe/81279>\
**Category:** Android Apprentice\
**Created:** [September 9, 2019, 3:27pm UTC](https://forums.kodeco.com/t/recyclerview-swipe/81279 "2019-09-09T15:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![keldii](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/keldii/32/110937_2.png) [@keldii](https://forums.kodeco.com/u/keldii)\
**Post date:** [September 9, 2019, 3:27pm UTC](https://forums.kodeco.com/t/recyclerview-swipe/81279/1 "2019-09-09T15:27:35Z")

</div>

Hi everyone,

I am a newbie on Android Development. I have a question about the RecyclerView’s swipe :  
Is it possible to enable the swipe just ONLY for some items and not for the whole ?

---

<div class="post-metadata">

**Author:** ![daemonic\_daz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/daemonic_daz/32/108563_2.png) [@daemonic\_daz](https://forums.kodeco.com/u/daemonic_daz)\
**Post date:** [September 14, 2019, 12:03pm UTC](https://forums.kodeco.com/t/recyclerview-swipe/81279/2 "2019-09-14T12:03:12Z")

</div>

Hey @keldii,

Good to hear from you. 🙂

Yes, it is possible to enable the swipe for some items.

I’ve taken the project from the [Android RecyclerView tutorial](https://www.raywenderlich.com/1560485-android-recyclerview-tutorial-with-kotlin), then updated the `setRecyclerViewItemToucherListener` method.

```auto
private fun setRecyclerViewItemTouchListener() {

    val itemTouchCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
      override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, viewHolder1: RecyclerView.ViewHolder): Boolean {

        return false
      }

      override fun onSwiped(viewHolder: RecyclerView.ViewHolder, swipeDir: Int) {

       // If the Viewholder is a PhotoHolder type, swipe it away!
        if(viewHolder is RecyclerAdapter.PhotoHolder) {
          val position = viewHolder.adapterPosition
          photosList.removeAt(position)
          recyclerView.adapter!!.notifyItemRemoved(position)
        } else {
          // We have a different view holder type, don't do anything!
        }
      }
    }

    val itemTouchHelper = ItemTouchHelper(itemTouchCallback)
    itemTouchHelper.attachToRecyclerView(recyclerView)
  }

```

The `ItemTouchHelper.onSwiped` method contains a `RecyclerView.ViewHolder` object as a parameter, you can use the Viewholder to check if it’s an item you would like to be swiped away.

I’ve attached the project for you to try out, I also recommend going through the RecyclerView tutorial above.

Any questions, please let me know.

Darryl

[galacticon-check-recyclerview-item.zip](https://forums.kodeco.com/uploads/short-url/6e25TQloblQeTPmyWVxSabYy7Pp.zip) (347.5 KB)
