答えを探している人がいる場合、これは Kotlin を使用して実装した方法です。
パーセル可能なオブジェクト クラス
data class CollectedMilk(
@SerializedName("id")
var id: Int,
@SerializedName("igicuba")
var igicuba: Int,
@SerializedName("collector")
var collector: String?,
@SerializedName("collected")
var collected: Int,
@SerializedName("accepted")
var accepted: Int,
@SerializedName("standard")
var standard: String?,
@SerializedName("created_at")
var created_at: String?,
@SerializedName("updated_at")
var updated_at: String?,
): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readInt(),
parcel.readString(),
parcel.readInt(),
parcel.readInt(),
parcel.readString(),
parcel.readString(),
parcel.readString()
)
override fun describeContents(): Int {
return 0
}
override fun writeToParcel(parcel: Parcel?, int: Int) {
parcel?.writeInt(id)
parcel?.writeInt(igicuba)
parcel?.writeString(collector)
parcel?.writeInt(collected)
parcel?.writeInt(accepted)
parcel?.writeString(standard)
parcel?.writeString(created_at)
parcel?.writeString(updated_at)
}
companion object CREATOR : Parcelable.Creator<CollectedMilk> {
override fun createFromParcel(parcel: Parcel): CollectedMilk {
return CollectedMilk(parcel)
}
override fun newArray(size: Int): Array<CollectedMilk?> {
return arrayOfNulls(size)
}
}
}
次にフラグメントで
collectedMilkAdapter.onItemClick = { collectedMilk ->
Toast.makeText(
MccApp.applicationContext(),
"Collector: " + collectedMilk.collector,
Toast.LENGTH_LONG
).show()
val intent = Intent(MccApp.applicationContext(), CollectedMilkActivity::class.java)
val bundle: Bundle = Bundle()
bundle.putParcelableArrayList("collectedMilk", collectedMilkArrayList)
intent.putExtras(bundle)
activity?.startActivity(intent)
}
次に、別のアクティビティで私の詳細アクティビティ
グローバル変数
private lateinit var collectedMilk: ArrayList<CollectedMilk>
関数内または OnCreate アクティビティ
val bundle = intent.extras
collectedMilk = (bundle?.getParcelableArrayList<CollectedMilk>("collectedMilk") as ArrayList<CollectedMilk>)
Toast(this).showCustomToast(
this,
""+collectedMilk,
dark
)