companion object {
fun newInstance(categoryId: Int, brandsList: ArrayList<Int>): Fragment {
val fragment = CategoryAllAdsFragment()
fragment.arguments = Bundle()
fragment.arguments!!.putInt(Constant.CATEGORY_ID, categoryId)
fragment.arguments!!.putParcelableArrayList(Constant.BRANDS_LIST, brandsList)
return fragment
}
class BaseParcelable : Parcelable {
var value: Any
constructor(value: Any) {
this.value = value
constructor(parcel: Parcel) {
this.value = Any()
override fun writeToParcel(dest: Parcel?, flags: Int) {}
override fun describeContents(): Int = 0
companion object CREATOR : Parcelable.Creator<BaseParcelable> {
override fun createFromParcel(parcel: Parcel): BaseParcelable {
return BaseParcelable(parcel)
override fun newArray(size: Int): Array<BaseParcelable?> {
return arrayOfNulls(size)
}
然后使用这个类在片段之间或片段之间传递数据(Activty到片段)
要将列表从一个片段传递到另一个片段,例如:
companion object {
fun newInstance(categoryId: Int, brandsList: ArrayList<Int>): Fragment {
val fragment = CategoryAllAdsFragment()
fragment.arguments = Bundle()