Learn Pain Less

HomeOur TeamContact
Android
Multiple selection RecyclerView Android
Pawneshwer Gupta
Pawneshwer Gupta
August 31, 2017
1 min

Table Of Contents

01
Multiple selection RecyclerView Android
02
Looking for full source code of this project then fork from below link
03
Download demo APK from below link
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 MainActivity.java

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 RecyclerItemClickListener.java

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 MyAdapter.java

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

<resources>
<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>
</resources>

star this repo fork this repo

Download APK

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

recyclerviewmulti selection

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

How to fix blinking issue for RecyclerView notify changes
How to fix blinking issue for RecyclerView notify changes
June 06, 2018
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media