java - 在 TextView 中显示数组

标签 java android arrays textview

我想用随机数填充数组,但无法在 TextViewer 中显示我的数组casual[] - 帮帮我!

LanciaB.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

        int result = np2.getValue();
        int result2 = np.getValue();
        result = result == 0 ? 10 : result;

        int casual[] = new int[10];
        for(int i=0; i < result2; i++){
            casual[i] = (int) (Math.random()*10);
        }

        tv.setText(casual.toString());

        }
    });

最佳答案

使用重载Arrays#toString(int[])以数组作为参数的数组。

 Arrays.toString(casual)

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

相关文章:

android多选列表选择滚动上的随机元素

java - BaseExpandableListAdapter 的 getChildrenCount() 上出现 NullPointerException

python - 基于字典替换 NumPy 数组中的值并避免新值和键之间的重叠

c++ - Append 在 C++ 中的数组链接列表中不起作用

java - Mustache.java 和 Mustache.js 模板处理之间的不兼容性?

java - 图片尺寸不正确?

java - 错误: Could not find or load main class SOAPTester

java - 如何编写自己的 ListSelectionEvent?

Eclipse 中的 Android 和 Javah

arrays - 如何在 Flutter 中解析这个 JSON 数组?