1.定義List類
class ReCheckOrder() : Parcelable {
var begin: String? = null
var channel: Int = 0
var itemDTOList: ArrayList<ReCheckItem>? = null
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(begin)
parcel.writeInt(channel)
parcel.writeTypedList(itemDTOList)
}
override fun describeContents(): Int {
return 0
}
constructor(parcel: Parcel) : this() {
begin = parcel.readString()
channel = parcel.readInt()
itemDTOList = parcel.createTypedArrayList(ReCheckItem.CREATOR)
}
companion object CREATOR : Parcelable.Creator<ReCheckOrder> {
override fun createFromParcel(parcel: Parcel): ReCheckOrder {
return ReCheckOrder(parcel)
}
override fun newArray(size: Int): Array<ReCheckOrder?> {
return arrayOfNulls(size)
}
}
}
2.定義List中Item的類
class ReCheckItem() : Parcelable {
var date: String? = null
var type: Int = 0
constructor(parcel: Parcel) : this() {
date = parcel.readString()
type = parcel.readInt()
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(date)
parcel.writeInt(type)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<ReCheckItem> {
override fun createFromParcel(parcel: Parcel): ReCheckItem {
return ReCheckItem(parcel)
}
override fun newArray(size: Int): Array<ReCheckItem?> {
return arrayOfNulls(size)
}
}
}
3.啟動ListActivity
companion object {
var PARAM_INTENT_RECHECK_ENTITY = "PARAM_INTENT_RECHECK_ENTITY"
}
val intent = Intent()
//it 是ReCheckOrder的一個實例
intent.putExtra(PARAM_INTENT_RECHECK_ENTITY, it)
startActivity(intent.setClass(this,ProductActivity::class.java))
4.接受ProductActivity
var mReCheckOrder: ResponseStockReCheckTask.ReCheckOrder? = null
intent.let {
mReCheckOrder = intent.getParcelableExtra(ListActivity.PARAM_INTENT_RECHECK_ENTITY)
}