gpt4 book ai didi

java - 在 toast 数组列表中显示

转载 作者:行者123 更新时间:2023-12-02 00:29:03 25 4
gpt4 key购买 nike

如何在 toast 中显示我的数组列表..这是我的代码,但它没有显示数组中的完整项目..我的问题是什么?

public static  EditText txt1;
String ag;
public static ArrayList<String> playerList = new ArrayList<String>();
String playerlist[];

/** Called when the activity is first created.
* @param Public */
public void onCreate(Bundle savedInstanceState, Object Public) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);

// edittext1 or textview1
txt1 = (EditText) findViewById(R.id.editText1);
ag = txt1.getText().toString();

//add more items button
Button more = (Button) findViewById(R.id.button1);
more.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (txt1.getText().length() != 0) {
String ag = "Current Added Players:," + txt1.getText().toString() + txt1.getText().toString();
playerList.add(ag);
Toast.makeText(getBaseContext(), ag, Toast.LENGTH_SHORT).show();

Intent myIntent = new Intent(view.getContext(), Screen2.class);
myIntent.putExtra("Stringarray", playerList);
//startActivityForResult(myIntent, 0);
}
}
});
}

最佳答案

如果您的 ArrayList 是字符串或任何包装类对象,那么您可以按照此操作

ArrayList<String> a = new ArrayList<String>();
a.add("Hello");
a.add("World"); //similarly any other add statements
Toast.makeText(getBaseContext(), a+"", Toast.LENGTH_SHORT).show();

不需要转换为数组或迭代列表,因为当列表是 String 或包装类对象时,它们的 toString() 方法将返回值而不是十六进制逻辑地址。

因此,在这种情况下,您将收到一条显示消息

[Hello,World,...other elements what is stored in the arraylist]

关于java - 在 toast 数组列表中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9493290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com