Zim*_*Zim 0 android parcelable android-fragments kotlin
我是 kotlin 的新手,并试图将一个对象从我的适配器传递给一个片段。但是我在booklist. 它说Required: Parceleable Found: List<ResourcesList>?
我也试过使用putParcelableArrayListandputParcelableArray和Serializable但也有相同的类型不匹配。
我的数据模型如下所示:
@Parcelize
class ResourcesList (val id: Int,
val name: String,
val content: Contents,
val tags: List<Tags>) : Parcelable
@Parcelize
class Contents (val id: Int,
val producers: List<Producers>,
val categories: List<Categories>,
val isAvailable: Boolean): Parcelable
@Parcelize
class Producers (val name: String,
val role: String): Parcelable
@Parcelize
class Categories (val id: Int,
val name: String): Parcelable
Run Code Online (Sandbox Code Playgroud)
分段
class SeeAllFragment: Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.see_all_layout, container, false)
val bookslist = arguments.getParceleable("bookslist")
return view
}
companion object {
fun newInstance(bookslist: List<ResourcesList>?): SeeAllFragment {
val args = Bundle()
args.putParcelable("bookslist", bookslist)
val fragment = SeeAllFragment()
fragment.arguments = args
return fragment
}
}
}
Run Code Online (Sandbox Code Playgroud)
将列表放入包中:
args.putParcelableArrayList("bookslist", bookslist as ArrayList<out Parcelable>?)
Run Code Online (Sandbox Code Playgroud)
获取列表:
val bookslist = arguments.getParcelableArrayList<ResourcesList>("bookslist")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2477 次 |
| 最近记录: |