Android中使用Intent传递对象(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-20 07:51 点击:次
package com.ldq.parcelable;
import android.os.Parcel;
import android.os.Parcelable;
public class Student implements Parcelable {
public int _id;
public String name;
public int sex;
public int age;
Student(Parcel p) {
_id = p.readInt();
name = p.readString();
sex = p.readInt();
age = p.readInt();
}
Student() {
};
public static final Parcelable.Creator<Student> CREATOR = new Parcelable.Creator<Student>() {
public Student createFromParcel(Parcel p) {
return new Student(p);
}
public Student[] newArray(int size) {
return new Student[size];
}
};
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel p, int flags) {
p.writeInt(_id);
p.writeString(name);
p.writeInt(sex);
p.writeInt(age);
}
}
AnotherActivity.java 文件:
Java代码
package com.ldq.parcelable;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class AnotherActivity extends Activity {
private TextView textView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Student s = getIntent().getParcelableExtra("student");
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>