【问题标题】:Android - How to pass HashMap<String,List<String>> between activities?Android - 如何在活动之间传递 HashMap<String,List<String>>?
【发布时间】:2014-03-14 13:00:04
【问题描述】:

我想通过意图传递 HashMap 对象。我的 Hashmap 包含字符串和列表。 HashMap> listDataChild;我想将 listDataChild 传递给下一个活动?

【问题讨论】:

    标签: android


    【解决方案1】:

    试试下面的代码:

    Intent intent=new Intent(CURRENT CLASS.this, CLASS TO CALL.class);
                        intent.putExtra("test", YOUR HASHMAP);
                        startActivity(intent);
    

    在另一个 Activity 中获取如下数据:

    HashMap<String, List<String>> data=(HashMap<String, List<String>>) this.getIntent().getSerializableExtra("test");
    

    【讨论】:

    • List 不是serializabe ..你可以通过ArrayList
    • 我已将我的列表定义为 List list112 = new ArrayList();
    • 所以你可以像@pratik所说的那样发送。
    【解决方案2】:

    将其作为Bundle 的一部分附加到 Intent。 HashMapSerializable,因此它可以在 BundleExtra 中工作。

    【讨论】:

      猜你喜欢
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      相关资源
      最近更新 更多