【问题标题】:Type mismatch.Required: MutableList<out ExpandableGroup<Parcelable>>类型不匹配。必需:MutableList<out ExpandableGroup<Parcelable>>
【发布时间】:2019-05-31 04:52:24
【问题描述】:

我正在尝试进行 expandale recyclerview,并且我使用了thoughtbot/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) {

}

【问题讨论】:

    标签: android kotlin parcelable expandablerecyclerview


    【解决方案1】:

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

    【讨论】:

    • 我改成这个。但没有效果 @SuppressLint(value = ["ParcelCreator"]) class Item(title: String, items: MutableList) : ExpandableGroup(title, items) { }
    【解决方案2】:

    已解决。刚刚改了

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 2021-09-17
      • 2020-06-19
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      相关资源
      最近更新 更多