Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

How to split Recycler view into 2 divisions based on type from a JSON file in Kotlin - in android studio ?

By M.K. Verma · 4 May 2022

How to split Recycler view into 2 divisions based on type from a JSON file in Kotlin - in android studio ?

I ended up filtering through my json file and splitting it into 2 lists. One that contains all the card types, another for all the bank types. Then passing each through their individual recycler.

val cardData: MutableList <Data> = mutableListOf<Data>()
        val bankData: MutableList <Data> = mutableListOf<Data>()

        for(i in data) {
            if (i.account_type.equals("card")){
                cardData.add(i)
        }
    }

        for(i in data) {
            if (i.account_type.equals("bank")){
                bankData.add(i)
            }
        }

To clarify, data is a list that uses the helper class Data using Gson, assign the json file to it in my main activity.