【问题标题】:How to pass Arraylist<bean> from oneactivity to another activity in android如何将 Arraylist<bean> 从一个活动传递到 android 中的另一个活动
【发布时间】:2014-07-22 07:52:27
【问题描述】:

我尝试了 intent.putExtra("listname", list) 和共享偏好列表。但它没有给出实际结果。帮我解决这个问题

Intent intent=new Intent(HotelSearch.this, HotelSearchResults.class); intent.putExtra("listname", list);

第二个活动:

hotelsearchresult=(ArrayList)intent.getSerializableExtra("listname");

【问题讨论】:

  • 您需要更加具体。发生了什么,您期望发生什么,在 logcat 中发现任何错误,并发布正在使用的确切代码。

标签: android list android-activity android-listview arraylist


【解决方案1】:

你必须使用可序列化的模型

intent.putExtra("MyClass", obj);  
getSerializableExtra("MyClass");

你的模型会是这样的;

public class City implements Serializable {

public String Name;
public String Name_EN;
public int ID;
}

更多答案请点击此链接:https://stackoverflow.com/a/2736612/3098590

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 2015-02-08
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    相关资源
    最近更新 更多