Multi-feature Recyclerview in android – Swipe to show options, drag (with handle also), filter enabled

Multi-feature Recyclerview in android - Swipe to show options, drag (with handle also), filter enabled

Whats new added in this:

1) Swipe item to show option like delete, show, edit

2) Custom layout for options by xml only, no code for view

3) Drag item to re-position

4) Rotate while dragging

5) Drag item with view like handle to drag

6) Search filter optimized

Here is example usage of BaseRecyclerView. Check code on github if want to check actual code of BaseRecyclerView.

import `in`.thejadav.baserecyclerview.BaseViewHolder
import android.os.Bundle
import android.view.View

class ExampleListHolder(view: View) : BaseViewHolder(view) {

    init {
        itemView.ivDelete.setOnClickListener {
            listener?.holderItemClicked(adapterPosition,, Bundle())

    override fun setItem(t: String) {
        itemView.textView.text = t

    override fun itemSelected() {

    override fun itemCleared() {

import `in`.thejadav.baserecyclerview.BaseRvAdapter
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup

class ExmpleStringAdapter(handleId: Int, hiddenViewId: Int, mainViewId: Int, var listener: ExampleStringListener) : BaseRvAdapter(handleId = handleId, hiddenViewId = hiddenViewId, mainViewId = mainViewId, dragEnabled = true) {
    override fun holderItemClicked(position: Int, viewId: Int?, bundle: Bundle?) {

    override fun itemMoved(position: Int) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExampleListHolder {
        return ExampleListHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_example, parent, false))

interface ExampleStringListener{
    fun deleteItem(s: String)
    fun itemDraged()

import android.os.Bundle
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager

class MainActivity : AppCompatActivity(), ExampleStringListener {
    private lateinit var adapter: ExmpleStringAdapter

    override fun onCreate(savedInstanceState: Bundle?) {

        adapter = ExmpleStringAdapter(,,,this)
        rvExample.layoutManager = LinearLayoutManager(this)
        rvExample.adapter = adapter

        val myList = arrayListOf("Hello", "Good Morning", "How", "Are", "You","Hello", "Good Morning", "How", "Are", "You")

    override fun deleteItem(s: String) {
        Toast.makeText(this, "Delete $s", Toast.LENGTH_SHORT).show()

    override fun itemDraged() {
        Toast.makeText(this, "Item Draged", Toast.LENGTH_SHORT).show()

Share this content:


More Posts

How does data persistence work in Android?

Data persistence in Android is the ability to save data to the device so that it can be accessed later, even if the app is closed or the device is restarted. There are several ways to achieve data persistence in Android

Fragments and Activities: Two Pillars of Android Development

Fragments and Activities are both important components of Android development. Fragments are a good choice for creating reusable and dynamic UIs, while Activities are a good choice for managing the lifecycle of an app’s UI and implementing core features.

Table of Contents

Send Us A Message