Vote count:
0
I'm trying to get shuffle character from String Question. But the character is repeated.
Random Method
public ArrayList<Integer> Random(int length) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i=0; i<length; i++) {
list.add(new Integer(i));
}
Collections.shuffle(list);
return list;
}
MainActivity
strQuestion = c.getString("question");
int length = strQuestion.length();
str_buff.getChars(0, length, char_text, 0);
for(int i=0;i<length;i++){
int k = Random(length).get(i);
TextView tv = new TextView(this);
tv.setText(String.valueOf(char_text[k]));
tv.setId(k);
tv.setTextSize(30);
tv.setBackgroundColor(0xff00ff00);
tv.setPadding(5, 5, 5, 5);
tv.setOnTouchListener(new MyTouchListener());
layout.addView(tv);
}
asked 34 secs ago
Generating Unique Random number JAVA
Aucun commentaire:
Enregistrer un commentaire