数组的捆绑数组不起作用-Android [英] Bundle array of arrays is not Working - Android

查看:68
本文介绍了数组的捆绑数组不起作用-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试捆绑一个阵列数组,但无法正常工作.以下是一段代码,可让您更好地理解:

Im tryin to bundle an Array of Arrays but is not working. Heres a snipped of code for better understanding:

声明和初始化变量

Inversor[][] reg_equipment= new Inversor[7][5];
for(int i=0; i<7; i++)
{
  for(int j=0;j<5;j++)
  {
    reg_equipment[i][j]= new Inversor();
  }
}
//....

将变量放入包中

bundle.putSerializable("reg_equipment", reg_equipment);

Intent myIntent =new  Intent(RegisterEquipmentInversor.this,RegisterEquipmentMain.class);
                myIntent.putExtras(bundle);

                startActivity(myIntent);

这时,reg_equipment中充满了Inversors [Inversor [0],Inversor [1] ....,Inversor [6]] ,在这些内部有更多的Inversors.

At this point, the reg_equipment is filled with Inversors [Inversor[0],Inversor[1]....,Inversor[6]] and inside those There are more Inversors.

但是当我去获取"另一个班级中的捆绑包时

But when I go "get" the bundle in the other class

reg_equipment = (Inversor[][]) extras.getSerializable("reg_equipment");

这是reg_equipment内部的内容- [Object [0],Object [1],...,[Object [6]] 在这些对象内部有逆变器.为什么会发生这种情况?我该如何解决?

This is whats inside de reg_equipment - [Object[0],Object[1],...,[Object[6]] and inside those Objects there are Inversors. Why does this happens ? How can I fix it ?

Inversor类实现了Serializable

谢谢

推荐答案

您应该尝试创建一个仅具有一个属性的Serializable类,该类应该是Inversor数组的数组,并将该对象放入您的意图中.像

You should try to create a Serializable class that has only one property, which should be your array of Inversor arrays and put that object in your intent. something like

public class InversorArrays implements Serializable {
    public final static int serialVersionUID = //let eclipse generate your uid
    public Inversor[][] myArray = null;
    public InversorArrays (Inversor[][] _myArray){
        this.myArray = _myArray;
    }
}

然后在您的活动中,创建一个InversorArrays实例并将其传递给意图

and then, in your activity, create an instance of InversorArrays an pass it to the intent

当然,Inversor及其属性也应该可序列化.

Of course, Inversor and its properties should be serializable too.

这种解决方法有时为我节省了很多时间,也为我节省了类型转换和转换方面的问题

This workaround sometimes saved me a lot of time and problems with typecasting and conversion problems

这篇关于数组的捆绑数组不起作用-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆