Multiple selection RecyclerView Android

Fetching Comments ...
Multiple selection RecyclerView Android

Multiple selection RecyclerView Android

Android RecyclerView multi selection expand list items and change list items color

Hello Devs, If you are previously working with ListView and recently shifted to RecyclerView then you maybe missing some great features like ItemClickListener, MultipleItemSelection, TouchRippleEffect,EmptyView and more.

But in RecyclerView we need to do this manually, so lets add MultiSelection functionality in RecyclerView.

Lets start:

code of

Description : So i created a boolean variable to check of multiple selection is active or not. and a List<Integer> selectedIds containing values which are selected. In RecyclerView's onItemTouchListener i used custom implementation of RecyclerView.OnItemTouchListener, for handling click and longClick events.

code of

On longClick we will check if multiSelection is false then set this to true. On singleClick or LongClick check if currently selected item is in List<Integer> selectedIds is list then remove that item from list, otherwise add that item in list and notify adapter for latest value. In adapter check if selectedItem match with current item in adapter then change backgroud or foreground color as per your choice.

code of

in onBindViewHolder method we will check if our selected items list contain current item then change its color to desired color to show as selected item, otherwise set color to transparent to show this like unselected item.

colors used in this demo

    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colorActionMode">#009362</color>
    <color name="colorControlActivated">#50FF4081</color>

Looking for full source code of this project then fork from below link

star this repo fork this repo

Download demo APK from below link

Download APK

Share This:

Featured Posts

post preview
post preview
post preview
post preview
post preview


Related Posts

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.