gpt4 book ai didi

android - 使用可序列化发送对象数组列表

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:24:58 28 4
gpt4 key购买 nike

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

我的代码是:

fragment :

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

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

Activity :

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

field 等级:

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;
}
}

最佳答案

尝试这种方式可能对你有帮助

首先你要制作

Venue 类实现 Serializable

public class Venue implements Serializable {
/**
*
*/

private static final long serialVersionUID = 1L;

}

在你的 FirstActivity 中这样做

  ArrayList<Venue> VenueArrayList = new ArrayList<Venue>();

Intent intent = new Intent(this,secondActivity.class);
intent.putExtra("VenueArrayList", VenueArrayList);

在您的 SecondActivity 中这样做

  ArrayList<Venue> VenueArrayList;
VenueArrayList = (ArrayList<Venue>) getIntent().getSerializableExtra(
"VenueArrayList");

关于android - 使用可序列化发送对象数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31335828/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com