Search code examples
androidlistviewgenericsarraylistadapter

Listview for Multiple model class


how to create a listview adapter on Android Studio(Java) for multiple model class which extending parent class.

so : gbpClass extends Money => ArrayList eurClass extends Money => ArrayList

I want to create list with gbpClass items and eurClass items. 1 button will show gbp list items. 1 button will show eur list items. But I will use 1 adapter class and it's Arraylist object can be contain gbp or eur list items.


Solution

  • By looking at your problem statement and with whatever information you have provided I think if you are only trying to show Euro and GBP data in your list then it's better not to complicate it and create single class for both

    e.g.

    data class Money(var amount: Double, var currency:String)