Skip to content
Advertisement

How to get arraylist from recyclerview adapter in android kotlin

I have recyclerView which is having multiple items. Every item is holding a checkbox to select that item. I want to get the selected item in another ArrayList and pass it to my MainActivity. On accept click I called getselecteditem() but getselecteditem() function always returns null. Here is my adapter code.

JavaScript

My MainActivity layout

Advertisement

Answer

  1. You need a callback which lets to fetch selected order and update list on every selected or un-select order
JavaScript
  1. orderAdapter constructor will have listener instance which will update selected list in main activity.
JavaScript
  1. In MainActivity recyclerview listener will get list.
JavaScript

orderAdapter class

JavaScript
Advertisement