3 回答

TA貢獻1893條經(jīng)驗 獲得超10個贊
您的 SectionDataModel 需要實現(xiàn) Parceble 接口。如下所示,您可以實施 -
public class Person implements Parcelable{
String name;
int age;
String sex;
public Person(String name, int age, String sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
public static final Creator<Person> CREATOR = new Creator<Person>() {
@Override
public Person createFromParcel(Parcel in) {
return new BeanClass(in);
}
@Override
public Person[] newArray(int size) {
return new Person[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(age);
dest.writeString(sex);
}
}
將數(shù)據(jù)從您的適配器類傳遞到片段或活動 -
@Override
public void onClick(View v){
Toast.makeText(v.getContext(), tvTitle.getText(), LENGTH_SHORT).show();
//passing data to Tab1Fragment
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("SectionDataModels", sectionDataModelList);
intent1.putExtras(bundle);
mContext.startActivity(intent1);
}
在活動中接收 SectionDataModelList -
ArrayList<SectionDataModel> listFromActivity =new ArrayList<>();
listFromActivity=this.getIntent().getExtras().getParcelableArrayList("SectionDataModels");
if (listFromActivity1 != null) {
Log.d("listis",""+listFromActivity1.toString());
}
此外,您可以嘗試通過這種方式接收意圖數(shù)據(jù) - 如果您需要
Bundle bundle = getActivity().getIntent().getExtras();
model = bundle.getParcelable("SectionDataModels");
OR
Bundle bundle = this.getArguments();
if (bundle != null) {
model = bundle.getParcelable("SectionDataModels");
}

TA貢獻1828條經(jīng)驗 獲得超6個贊
您可以將 arraylist 保留在您的應用程序類中而不是第一個活動中(因為它在整個應用程序中都是相同的),然后只需使用 intent1.putExtra("position",position)
.
在活動 2 中使用
int position = getIntent().getIntExtra("position")
現(xiàn)在只需使用此位置從應用程序類數(shù)組列表中獲取模型類對象。
添加回答
舉報