我正在提问和回答。我的问题随机产生,但问题再次重复。
我使用txt文件作为我的数据库当int数组随机生成我的持有者得到我的数据库中的字符串行。应该是int array = x,和string line = y; {Y == X}。我的问题是,当我再次生成问题再次,我想我会做什么?。
private void question() {
InputStreamReader inputStream = new InputStreamReader
(getResources().openRawResource(R.raw.question1));
BufferedReader br = new BufferedReader(inputStream);
ArrayList<Integer> ar= new ArrayList<Integer>();
int[] number= {1,2,3,4,5,6,7,8,9,10};
for (int i : number) {
ar.add(i);
}
Random r = new Random();
int select = r.nextInt(ar.size());
int random = ar.get(select);
ar.remove(select);
String theLine="";
int lineCtr = 0;
try {
while ((theLine = br.readLine()) != null) {
if (lineCtr == select) {
StringTokenizer st = new StringTokenizer(theLine,",");
while(st.hasMoreTokens())
{
//reading and getting data from the database","
String a = st.nextToken();
String b = st.nextToken();
String c = st.nextToken();
String d = st.nextToken();
String e = st.nextToken();
String f = st.nextToken();
//button setText
question.setText(a);
ca.setText(f);
firstbutton.setText(e);
secondbutton.setText(d);
thirdbutton.setText(b);
fourthbutton.setText(c);
//assigning
firstholder =e;
secondholder =d;
thirdholder=b;
fourthholder =c;
break;
}
}lineCtr++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:0)
您是否尝试过以下代码来解决重复问题: -
Collections.shuffle(Arrays.asList(number));