通过意图传递的ArrayList意图、ArrayList

2023-09-11 12:47:34 作者:别用吻过她的嘴说爱我

我试图到一个ArrayList通过使用意图另一个活动。这里是code。在第一个活动。

 案例R.id.editButton:
        Toast.makeText(这一点,编辑被点击Toast.LENGTH_LONG).show();
        意向意图=新的意图(这一点,editList.class);
        intent.putStringArrayListExtra(stock_list,stock_list);
        startActivity(意向);
        打破;
 

这是我尝试检索列表中的第二个活动。有什么不对吗?

 意向书我=新意图(); //这应该是getIntent();
    stock_list =新的ArrayList<字符串>();

    stock_list = i.getStringArrayListExtra(stock_list);
 

解决方案 Android中的Activity通过显式意图传值

在你接收的意图,你需要做的:

 意图I = getIntent();
stock_list = i.getStringArrayListExtra(stock_list);
 

你拥有了它你就创建了一个新的空的意图没有任何额外的方式。

如果你只有一个额外的,你可以凝聚下来到:

  stock_list = getIntent()getStringArrayListExtra(stock_list)。
 

I am trying to pass an arrayList to another activity using intents. Here is the code in the first activity.

case R.id.editButton:
        Toast.makeText(this, "edit was clicked", Toast.LENGTH_LONG).show();
        Intent intent = new Intent(this, editList.class);
        intent.putStringArrayListExtra("stock_list", stock_list);
        startActivity(intent);
        break;

This is where I try to retrieve the list in the second activity. Is something wrong here?

Intent i = new Intent(); //This should be getIntent();
    stock_list = new ArrayList<String>();

    stock_list = i.getStringArrayListExtra("stock_list");

解决方案

In your receiving intent you need to do:

Intent i = getIntent();  
stock_list = i.getStringArrayListExtra("stock_list");

The way you have it you've just created a new empty intent without any extras.

If you only have a single extra you can condense this down to:

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