0

我正在尝试做expandale recyclerview,我使用thinkbot/expandable-recycler-view,但我的适配器有问题。也许有人有类似的问题,可以帮助我解决这个问题
1)我的父类的代码

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

2)子类(这里我使用了parcelize。但现在我使用: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 ****/
    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) {

}
4

2 回答 2

0

解决了。刚变

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

CartAdapter(groups: List<out ExpandableGroup<*>>)
于 2019-05-31T07:10:31.983 回答
0

我相信你的Item课程也应该是可包裹的。

于 2019-05-31T06:34:39.743 回答