[关闭]
@cxm-2016 2016-08-12T15:09:16.000000Z 字数 667 阅读 1559

Parcelable举例

android no


  1. public class User implements Parcelable {
  2. private String name;
  3. private int age;
  4. public String getName() {
  5. return name;
  6. }
  7. public void setName(String name) {
  8. this.name = name;
  9. }
  10. public int getAge() {
  11. return age;
  12. }
  13. public void setAge(int age) {
  14. this.age = age;
  15. }
  16. public User() {
  17. }
  18. private User(Parcel in) {
  19. name = in.readString();
  20. age = in.readInt();
  21. }
  22. public static final Parcelable.Creator<User> CREATOR = new Parcelable.Creator<User>() {
  23. @Override
  24. public User createFromParcel(Parcel source) {
  25. return new User(source);
  26. }
  27. @Override
  28. public User[] newArray(int size) {
  29. return new User[0];
  30. }
  31. };
  32. @Override
  33. public int describeContents() {
  34. return 0;
  35. }
  36. @Override
  37. public void writeToParcel(Parcel dest, int flags) {
  38. dest.writeString(name);
  39. dest.writeInt(age);
  40. }
  41. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注