Generic RecyclerView Adapter

Malwinder Singh
May 31, 2020

--

I’m writing this article in the situation when the whole world is lockdown due to Covid-19 but the developers don’t stop working 😁

Here is the code for generic RecyclerView Adapter:

Here’s how you can use it:

val apples = arrayListOf(
Apple(5f, 50f),
Apple(6f, 55f),
Apple(7f, 60f),
Apple(8f, 65f)
)

rv.showData(
apples, R.layout.rv_list_item
) { _, itemData, itemView ->
(itemView as TextView).text = itemData.size.toString()
}

apples.add(Apple(9f, 66f))
rv.refresh()

Hope you liked this article!

Medium does not allow Indian writers to monetize currently 😭. Please support this blog by contributing here: https://www.patreon.com/malwinder 🥰

Buy me a coffee 🥰

Even a small contribution would help 😍

If you have any questions, then please write down a response in the response section.
If you liked this article, then please press the 👏 icon.
Thank you!
Peace! 🙂

--

--

Malwinder Singh
Malwinder Singh

Written by Malwinder Singh

Flutter, Kotlin & Android. Worked on projects of Emerson and Omron, 50k+ views on this blog, 6k+ repo on StackOverflow, Drone startup linkedin.com/in/malwinder

No responses yet