Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将随机数设置为具有不同数字的Textview数?_Android_Random - Fatal编程技术网

Android 如何将随机数设置为具有不同数字的Textview数?

Android 如何将随机数设置为具有不同数字的Textview数?,android,random,Android,Random,我是android开发的新手。所以,我的问题是,我有一个LinearLayout,在这个LinearLayout中,我有28个TextView,在这个TextView中,我想向所有TextView显示随机数,这些随机数是由随机数生成的 当前:TextView向所有人显示相同的号码TextView但我想向所有人显示不同的号码TextView 这是我的版面截图: 所以,如果有人知道,请告诉我。首先使用下面的代码片段创建随机数的数组列表 ArrayList<Integer> arrayL

我是android开发的新手。所以,我的问题是,我有一个
LinearLayout
,在这个
LinearLayout
中,我有28个
TextView
,在这个
TextView
中,我想向所有
TextView
显示随机数,这些随机数是由随机数生成的

当前:
TextView
向所有人显示相同的号码
TextView
但我想向所有人显示不同的号码
TextView

这是我的版面截图


所以,如果有人知道,请告诉我。首先使用下面的代码片段创建随机数的数组列表

ArrayList<Integer> arrayList = new ArrayList<>();
Random random = new Random();

for (int i = 0; i < 28; i++) {
    arrayList.add(random.nextInt(28));
}
 int count = 0;
    for (int i = 0; i < parenView.getChildCount(); i++) {
        View view = parenView.getChildAt(i);
        if (view instanceof TextView) {
            TextView tvChild = (TextView) view;
            tvChid.setText(arrayList.get(count) + "");
            count++;
        }
    }

首先使用以下代码段创建随机数的
Arraylist

ArrayList<Integer> arrayList = new ArrayList<>();
Random random = new Random();

for (int i = 0; i < 28; i++) {
    arrayList.add(random.nextInt(28));
}
 int count = 0;
    for (int i = 0; i < parenView.getChildCount(); i++) {
        View view = parenView.getChildAt(i);
        if (view instanceof TextView) {
            TextView tvChild = (TextView) view;
            tvChid.setText(arrayList.get(count) + "");
            count++;
        }
    }

让我们看看你想要什么tried@andrei我使用了一个随机变量,这个变量我已经设置为所有textview,但它对所有textview显示相同的数字tried@andrei我使用一个随机变量,这个变量我已经设置为所有文本视图,但它显示的数字与所有文本视图的数字相同。谢谢你的帮助。非常简单的回答谢谢你的帮助很简单的答案