Jasur Jiyanbaev
Jasur Jiyanbaev

Reputation: 67

Type mismatch.Required: MutableList<out ExpandableGroup<Parcelable>>

I'm trying to do expandale recyclerview and I use thoughtbot/expandable-recycler-view, but I've problem with adapter. Maybe someone had similar problem and can help me to solve this problem
1) code of my Parent Class

/****** parent ******/
class Item(title: String?, items: MutableList<ItemDetail>?) : 
ExpandableGroup<ItemDetail>(title, items)

2)Child class (here I used parcelize. but now I use :Parcelable)

 // @Parcelize
 // data class ItemDetail(
 // var i_size: String,
 // var i_qty: Int
 //): Parcelable
 class ItemDetail (val i_size: String, val i_qty: Int): Parcelable{
    constructor(parcel: Parcel):this(
     parcel.readString(),
     parcel.readInt()){

   }

   override fun writeToParcel(parcel: Parcel, flags: Int) {
      parcel.writeString(i_size)
      parcel.writeInt(i_qty)
   }

   override fun describeContents(): Int {
     return 0
    }

  companion object CREATOR : Parcelable.Creator<ItemDetail> {
     override fun createFromParcel(parcel: Parcel): ItemDetail {
       return ItemDetail(parcel)
     }

     override fun newArray(size: Int): Array<ItemDetail?> {
      return arrayOfNulls(size)
     }
 }
 }

3) Fragment - Adapter





    /**** fragment ****/
    val groups: MutableList<Item> = ArrayList<Item>()

    val childs : MutableList<ItemDetail> = ArrayList<ItemDetail>()
    childs.add(ItemDetail("200x200",4))
    childs.add(ItemDetail("300x300",6))
    childs.add(ItemDetail("400x300",2))
    groups.add(Item("Item ISFAKHAN",childs))

    val childs2 : MutableList<ItemDetail> = ArrayList<ItemDetail>()
    childs2.add(ItemDetail("200x200",42))
    childs2.add(ItemDetail("300x300",62))
    childs2.add(ItemDetail("400x300",22))
    groups.add(Item("Item DASTAN",childs2))
    /***  error ***/
    cAdapter = CartAdapter(groups)
    /*** Type mismatch.Required: MutableList<out ExpandableGroup<Parcelable>>? Found: MutableList<Item> ***/



      /****** adapter *****/
    class CartAdapter(groups: MutableList<out ExpandableGroup<Parcelable>>?) : 
    ExpandableRecyclerViewAdapter<ItemVH, ItemDetailVH>(groups) {

}

Upvotes: 0

Views: 1750

Answers (2)

Jasur Jiyanbaev
Jasur Jiyanbaev

Reputation: 67

SOLVED. just changed

CartAdapter(groups: MutableList<out ExpandableGroup<Parcelable>>?)

to

CartAdapter(groups: List<out ExpandableGroup<*>>)

Upvotes: 0

r2rek
r2rek

Reputation: 2263

I believe that your Item class should also be parcelable.

Upvotes: 0

Related Questions