我到处搜索,甚至在android网页上,但我没有发现任何东西。我试图传递一个类的Arraylist:“ArrayList”从意图a到意图b,但总是我有问题,传输数据但是当脚本尝试从意图转换为parcelable或者其他什么时,我只得到“ null ”。我正在复制代码;
public class MedicalService implements Parcelable{
String MSrName;
String MSrValue;
String FnsValue;
String Clinica;
/*i deleted the getters and setters*/
//------------------------PARCELABLE-----------------------
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(MSrName);
dest.writeString(MSrValue);
dest.writeString(FnsValue);
dest.writeString(Clinica);
}
public static final Parcelable.Creator<MedicalService> CREATOR = new Parcelable.Creator<MedicalService>() {
@Override
public MedicalService createFromParcel(Parcel arg0) {
// TODO Auto-generated method stub
return new MedicalService(arg0);
}
@Override
public MedicalService[] newArray(int arg0) {
// TODO Auto-generated method stub
return new MedicalService[arg0];
}
};
public MedicalService(Parcel in){
this();
MSrName = in.readString();
MSrValue = in.readString();
FnsValue = in.readString();
Clinica = in.readString();
}
public MedicalService() {
// TODO Auto-generated constructor stub
}
}
这是意图A
MedicalService ms = new MedicalService(null);
ArrayList<MedicalService>lMS = new ArrayList<MedicalService>();
ms = xml_h.getMedicalService(session.getUsrMobileSessionCode(), idClinica , MSrCode);
ms.setClinica(clinica);
lMS.add(ms);
Intent i = new Intent(User.this,Result.class);
i.putParcelableArrayListExtra("MS_", lMS);
startActivity(i);
这是意图B(我收到了“加注”)
ArrayList<MedicalService> lMS = new ArrayList<MedicalService>();
Intent intent = getIntent();
Parcelable[] ps = intent.getParcelableArrayExtra("MS_");
我尝试了一切,有很多方法来传递信息,即使使用Serializable,但是这不允许我放置一个arraylist。当我创建这个类的一个实例时,出现一个错误,告诉我我的类需要初始化,但是使用Parcel
ms = new MedicalService(null);