从按钮

时间:2016-05-05 21:25:03

标签: java android button

我有三个字符串数组,每个字符串大约40个字。我需要一个按钮:

  • 从每个数组中随机选择一个字符串
  • 在相应的textView框中显示每个字符串
  • 并且在运行期间不会重复先前的选择。

我没有任何代码示例,但我迷失在哪里想弄明白或如何创建我需要的方法和类。

1 个答案:

答案 0 :(得分:0)

请尝试以下

// Assuming you have textViews declared and the arrays
int index = Math.random()*array1.length();
textView1.setText(array1[index]);
index = Math.random()*array2.length();
textView2.setText(array2[index]);
index = Math.random()*array3.length();
textView3.setText(array3[index]);

将此代码放在您想要的位置