Home > Net >  Listview for Multiple model class
Listview for Multiple model class

Time:05-16

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.

CodePudding user response:

I thought, if I create an arraylist which contains Money items maybe I fix this issue. Because gbp items or eur items already subtype of Money. But I wonder about doing this feature with polymorphism.

CodePudding user response:

Have you tried ArrayList<? extends Money> as a arraylist type?

CodePudding user response:

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)
  • Related