Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Parceable object passing Class object list in android
- public class OrderedData implements Parcelable
- {
- private String _title, _subtitle, _person_type, _processed_name;
- private Integer _price, _quantity;
- public OrderedData(String title, String subtitle, String person_type, String processed_name, Integer price, Integer quantity)
- {
- _title = title;
- _subtitle = subtitle;
- _person_type = person_type;
- _processed_name = processed_name;
- _price = price;
- _quantity = quantity;
- }
- public OrderedData(Parcel in)
- {
- // TODO Auto-generated constructor stub
- String[] data = new String[6];
- in.readStringArray(data);
- _title = data[0];
- _subtitle = data[1];
- _person_type = data[2];
- _processed_name = data[3];
- _price = Integer.parseInt(data[4]);
- _quantity = Integer.parseInt(data[5]);
- }
- public String getTitle()
- {
- return _title;
- }
- public String getSubTitle()
- {
- return _subtitle;
- }
- public String getPersonType()
- {
- return _person_type;
- }
- public String getProcessedName()
- {
- return _processed_name;
- }
- public Integer getPrice()
- {
- return _price;
- }
- public Integer getQuantity()
- {
- return _quantity;
- }
- @Override
- public int describeContents()
- {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void writeToParcel(Parcel dest, int flags)
- {
- dest.writeStringArray(new String[]
- { this._title, this._subtitle, this._person_type, this._processed_name, String.valueOf(this._price), String.valueOf(this._quantity) });
- }
- public static final Parcelable.Creator<OrderedData> CREATOR = new Parcelable.Creator<OrderedData>()
- {
- public OrderedData createFromParcel(Parcel in)
- {
- return new OrderedData(in);
- }
- public OrderedData[] newArray(int size)
- {
- return new OrderedData[size];
- }
- };
- }
- FirstActivity Android
- ArrayList<OrderedData> list = new ArrayList<OrderedData>();
- list.add(new OrderedData("abc", "abc", "abc", "abc", 1, 1));
- list.add(new OrderedData("abc", "abc", "abc", "abc", 1, 1));
- list.add(new OrderedData("abc", "abc", "abc", "abc", 1, 1));
- Intent intent = new Intent(MainActivity.this, SecondActivity.class);
- intent.putParcelableArrayListExtra("data", list);
- startActivity(intent);
- SecondActivity Android
- List<OrderedData> list=getIntent().getParcelableArrayListExtra("data");
- int a=10;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement