我想将两个ArrayList项目从我的主要活动传递给我使用的另一个活动。但是每次,它仅将最后一项传递给每个ArrayList。如何在一个意图和捆绑中传递两个ArrayList项目?

-ResponseActivity.java-

//buttonStatusListener()

private OnClickListener buttonStatusListener = new OnClickListener()
{
    public void onClick(View v)
    {
        Intent i1 = new Intent(ResponseActivity.this, StatusActivity.class);

        ArrayList<String> code = new ArrayList<String>();
        code = parseddata.getCode();
        ArrayList<String> request = new ArrayList<String>();
        request = parseddata.getRequest();

        Bundle b = new Bundle();
        b.putStringArrayList(StatusActivity.TEXT_REQUEST, request);
        b.putStringArrayList(StatusActivity.TEXT_CODE, code);



        i1.putExtras(b);

        startActivity(i1);
    }
};


-状态活动-

public class StatusActivity extends Activity{


 ParsedDataList parseddata = null;

public static String TEXT_CODE;
public static String TEXT_REQUEST;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    parseddata = MyXMLHandler.getExampledata();

    TextView textCode[] = new TextView[parseddata.getCode().size()];
    TextView textRequest[] = new TextView[parseddata.getRequest().size()];

    Bundle extras = getIntent().getExtras();
    ArrayList<String> code = new ArrayList<String>();
    code = extras.getStringArrayList(TEXT_CODE);
    ArrayList<String> request = new ArrayList<String>();
    request = extras.getStringArrayList(TEXT_REQUEST);

    LinearLayout lLayout = new LinearLayout(this);
    lLayout.setOrientation(1);


    for(int i = 0; i < parseddata.getRequest().size(); i++)
    {
        textCode[i] = new TextView(this);
        textCode[i].setText("Code: " + code.get(i));

        textRequest[i] = new TextView(this);
        textRequest[i].setText("Request: " + request.get(i));

        lLayout.addView(textCode[i]);
        lLayout.addView(textRequest[i]);
    }

        setContentView(lLayout);
}


ParsedDataList是我的数据类,我保存我的数据。它们的类型也是ArrayList<String>

最后,我的结果是:

Code: 200
Request: 200

最佳答案

您可以轻松地传递它们,只是两个键应该不同,您可以使用这些键获得这些值。

09-05 17:18