【问题标题】:Android send ArrayList the objectAndroid 发送 ArrayList 对象
【发布时间】:2018-11-03 20:17:10
【问题描述】:

我很笨拙。

解决我的问题

起源活动

    public void marcas(View view) {
    ArrayList<Localizacion> object = new ArrayList<Localizacion>(localizaciones);
    Intent intent = new Intent(getApplicationContext(), CompraVenta.class);
    Bundle args = new Bundle();
    args.putSerializable("ARRAYLIST", (Serializable) object);
    intent.putExtra("BUNDLE", args);
    startActivityForResult(intent, RESPUESTA_ACTIVIDAD);
}

命运活动

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compra_venta);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Intent intent = getIntent();
    Bundle args = intent.getBundleExtra("BUNDLE");
    ArrayList<Localizacion> object = (ArrayList<Localizacion>) args.getSerializable("ARRAYLIST");
    loc = object;
    enlaceInterfaz();
}

在 Localizacion 类中,我实现了 Parceable。 我的错误是想像在 java 类中使用它们一样使用数组,但这不是它的工作原理。

谢谢大家

【问题讨论】:

  • 请发布代码,而不是图片...
  • 欢迎来到 Stack Overflow!请将您的代码发布为代码,而不是图像。您应该将代码 sn-p 缩进 4 个空格以将它们放入 code markdown。使用帖子下方的“编辑”链接来编辑问题。

标签: android android-activity arraylist send


【解决方案1】:

将您的class 设为Parceable,然后您就可以将该类的对象列表传递给另一个Activity

class Localizacion implements Parceable {

}

现在发送数据到另一个Activity

intent.putParcelableArrayListExtra("array",object);

在接收方

loc = getIntent().getParcelableArrayExtra("array");

【讨论】:

    猜你喜欢
    • 2017-06-02
    • 2014-06-10
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    相关资源
    最近更新 更多