亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我無法將帶有一個片段的包的 ArrayList 放入另一個片段

我無法將帶有一個片段的包的 ArrayList 放入另一個片段

一只萌萌小番薯 2023-06-14 10:43:16
我想在另一個片段中使用我自己的數據類型的 ArrayList,我用一個包對其進行測試,并將列表與 putParcelableArrayList 方法放在一起,但它沒有用。任何想法為什么,或更好的建議?片段 1:Bundle arguments = new Bundle(); arguments.putParcelableArrayList("BESTAND", (ArrayList<Bestand>) palBestand);片段 2:ArrayList<Bestand> bestandsliste = (ArrayList<Bestand>) getArguments().getParcelableArrayList("BESTAND");
查看完整描述

1 回答

?
www說

TA貢獻1775條經驗 獲得超8個贊

這是 Parcelable 類的示例


public class Student implements Parcelable{

        private String id;

        private String name;

        private String grade;


        // Constructor

        public Student(String id, String name, String grade){

            this.id = id;

            this.name = name;

            this.grade = grade;

       }

       // Getter and setter methods

       .........

       .........


       // Parcelling part

       public Student(Parcel in){

           String[] data = new String[3];


           in.readStringArray(data);

           // the order needs to be the same as in writeToParcel() method

           this.id = data[0];

           this.name = data[1];

           this.grade = data[2];

       }


       @Оverride

       public int describeContents(){

           return 0;

       }


       @Override

       public void writeToParcel(Parcel dest, int flags) {

           dest.writeStringArray(new String[] {this.id,

                                               this.name,

                                               this.grade});

       }

       public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {

           public Student createFromParcel(Parcel in) {

               return new Student(in); 

           }


           public Student[] newArray(int size) {

               return new Student[size];

           }

       };

   }


查看完整回答
反對 回復 2023-06-14
  • 1 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號