相关疑难解决方法(0)

帮助传递ArrayList和parcelable Activity

所以我昨天一直在谷歌上搜索大部分时间,并且似乎无法绕过如何将一个arraylist传递给一个sublativity.有大量的示例和片段传递原始数据类型,但我所拥有的是类型为address的arraylist (下面是address.java).

我已经在stackoverflow和网络上发现了很多东西,但除了一个带有GeoPoint示例的东西之外没什么值得关注的.再次,它看起来像他们只是将GeoPoint对象扁平化为两个整数并将其传入.我不能这样做,因为我的地址类可能会扩展为包括整数,浮点数等等.现在,为简单起见,下面的测试应用程序只有两个字符串.我想如果我可以让parcelalbe的东西与之合作,其余的就可以了.

有人可以为非基本对象的ArrayList发布一个工作示例,或者可能在下面添加代码以使其工作吗?

更新:以下代码现在在回复/编辑后工作.谢谢!

/* helloParcel.java */        
       public class helloParcel extends Activity
{
    // holds objects of type 'address' == name and state
    private ArrayList <address> myList;

    @Override
    public void onCreate (Bundle savedInstanceState)
    {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.main);

        Button b1 = (Button) findViewById(R.id.button1);
        b1.setOnClickListener(ocl);

        myList = new ArrayList();
        address frank   = new address ("frank", "florida");
        address mary    = new address ("mary", "maryland");
        address monty   = new address ("monty", "montana");

        myList.add (frank);
        myList.add (mary);
        myList.add …
Run Code Online (Sandbox Code Playgroud)

android parcelable android-activity

31
推荐指数
4
解决办法
5万
查看次数

标签 统计

android ×1

android-activity ×1

parcelable ×1