简体   繁体   中英

how to display arrays using toast

I want to display an array of numbers using Toast function. But, it is accepting only strings. Is there any way to get rid of this problem?

您可以使用StringBuilder类从数组中构建所需的字符串。

To detail the answer of @Daniel:

int[] myArray = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
StringBuilder builder = new StringBuilder();
for(int i : myArray)
{
     builder.append("" + i + " ");
}
Toast.makeText(this, builder, Toast.LENGTH_LONG).show();

它可以简单地通过:

Toast.makeText(getApplicationContext(), Arrays.toString(nameSend), Toast.LENGTH_LONG).show();

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