简体   繁体   中英

Sending arrayList<string> with intent

I have made a list of names that I need to send to a different activity like this:

for(i=0;i<n;i++)
{
 imena[i] = player[i].toString();
}
    allPlayers = new ArrayList<String>();
    Collection l = Arrays.asList(imena);
    allPlayers.addAll(l); 

I'm not sure if this is correct, but then in the other activity I need to set the text of dynamically made EditText boxes to the names that I have set to my list, this is my try:

if(bundle!= null)
    {   


        allPlayers = bundle.getStringArrayList("allPlayers");
        for (i = 0;i<n;i++)
        {
                player[i] = new EditText(getApplicationContext());
                player[i].setTextSize(20);
                String p1 = allPlayers.get(i).toString();
                player[i].setText(p1);
                root.addView(player[i]);


        }
    }

As a result I get the EditBoxes filled with the text: "Android.widget.EditText{4085a09....}" any ideas how to get the actual names in those boxes?

You have:

 imena[i] = player[i].toString();

Note that player is an array of EditText, not String, so you need to call player[i].getText().toString() rather than player[i].toString() to get the value of the EditText.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM