使用可序列化发送对象数组列表 [英] Sending arraylist of objects using serializable

查看:28
本文介绍了使用可序列化发送对象数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的 JSON 数据存储到一个对象数组列表中,我的对象类是 Venue,我正在使用片段中的可序列化将该数据传递到另一个活动中,但我没有在活动中收到任何值.它正在接收额外的.捆绑不为空.

I am storing my JSON data into a arraylist of objects, my object class is Venue and I am passing that data into another activity using serializable from fragment but I am not receiving any values in the actvity. It is receiving the extra. bundle is not null.

我的代码是:

片段:

 Intent intent = new Intent(getActivity(), SearchVenueActivity.class);

 //pass values
 Bundle bundle = new Bundle();
 bundle.putSerializable("arrayListVenue",arrayListVenue);
 intent.putExtras(bundle);
 startActivity(intent);

活动:

if (getIntent().hasExtra("arrayListVenue")) {
    Bundle bundle = getIntent().getExtras();
    if(bundle!=null)
        rowItems = (ArrayList<Venue>) bundle.getSerializable("arrayListVenue");
    else
        Log.e("null","null");
}

场地等级:

public class Venue implements Serializable{

    String venue_id;
    String venue_name;
    String venue_address;
    String venue_city;

    public String getVenue_city() {
        return venue_city;
    }

    public void setVenue_city(String venue_city) {
        this.venue_city = venue_city;
    }

    public Venue(String venue_id, String venue_name, String venue_address, String venue_city, String venue_zip, String venue_phone, String venue_mobile) {
        this.venue_id = venue_id;
        this.venue_name = venue_name;
        this.venue_address = venue_address;
        this.venue_city = venue_city;

        this.venue_zip = venue_zip;
        this.venue_phone = venue_phone;
        this.venue_mobile = venue_mobile;
    }

    public String getVenue_id() {
        return venue_id;
    }

    public void setVenue_id(String venue_id) {
        this.venue_id = venue_id;
    }

    public String getVenue_name() {
        return venue_name;
    }

    public void setVenue_name(String venue_name) {
        this.venue_name = venue_name;
    } 
}

推荐答案

使用 intent.putParcelableArrayListExtra("arrayListVenue",arrayListVenue); 将 arraylist 放入 Intent 并使用 intent.getParcelableArrayExtra("arrayListVenue") 用于从 SearchVenueActivity 活动中的 Intent 中获取 arraylist
编辑parcelable 使用教程

Use intent.putParcelableArrayListExtra("arrayListVenue",arrayListVenue); for putting arraylist to intent and use intent.getParcelableArrayExtra("arrayListVenue") for get arraylist back from intent in your SearchVenueActivity activity
Edit Tutorial for using parcelable

这篇关于使用可序列化发送对象数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆