【问题标题】:how to send an arraList from one activity to another by using putExtra?如何使用 putExtra 将 arrayList 从一个活动发送到另一个活动?
【发布时间】:2014-04-29 12:53:58
【问题描述】:

我有四个不同的arrayLists,我想将该arrayList 值用于另一个活动,我想通过intent.extra 传递它们。所以有朋友可以告诉我怎么做。我的arr7ayLists 如下: ma​​in.java

completeOrderArray = new ArrayList<String>();
        productIdArray = new ArrayList<String>();
        orderProductIdArray = new ArrayList<String>();
        payeeKeyArray = new ArrayList<String>();

【问题讨论】:

标签: android android-intent arraylist


【解决方案1】:

你可以用in.putStringArrayListExtra代替intent.putExtra作为

in.putStringArrayListExtra("complete", completeOrderArray);
    in.putStringArrayListExtra("product", productIdArray);
    in.putStringArrayListExtra("order", orderProductIdArray);
    in.putStringArrayListExtra("payee", payeeKeyArray);

【讨论】:

    【解决方案2】:

    试试这个..

    Intent intent = new Intent(this, nextActivity.class);
    intent.putStringArrayListExtra("list", listObj);
    startActivity(intent);
    

    在下一个活动中

    stock_list = getIntent().getStringArrayListExtra("list");
    

    【讨论】:

      【解决方案3】:

      放置:

      intent.putExtra("list_tag", yourList);
      

      从其他活动中获取

      ArrayList<String> a = (ArrayList<String>) getIntent().getSerializableExtra("list_tag");
      

      【讨论】:

        【解决方案4】:

        在您的第一个活动中,使用:

        Intent intent = new Intent(this, secondActivity.class);
        intent.putStringArrayListExtra("list_data", data);
        startActivity(intent);
        

        在下一个活动中:

        dataList= getIntent().getStringArrayListExtra("list_data");
        

        【讨论】:

          【解决方案5】:

          只需将Intent.putExtra()StringSerializable 参数一起使用...或使用静态变量

          intent.putExtra("extra", (java.io.Serializable) yourArrayList);
          ...
          yourArrayList = (List<...>) intent.getSerializableExtra("extra");
          

          【讨论】:

            猜你喜欢
            • 2015-07-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-08-31
            • 1970-01-01
            相关资源
            最近更新 更多