I'm doing a simple random quiz app in Android. So basically I have string array of words. I need to display the string without repetition. This is what I've tried so far:
String[] words = { "Welcome", "Different", "Teenager", "Transfer", "Italian",
"Timber", "Toxic", "Illiterate", "Irate", "Moderate", "Transportation", "Attention" };
ArrayList<String> wordlist = new ArrayList<String>();
for (String i : words)
wordlist.add(i);
Collections.shuffle(wordlist);
randomStr = words[new Random().nextInt(words.length)];
tvWord.setText("");
tvWord.setText(randomStr);
But I still get the random word repeating. What am I doing wrong in here? Any ideas? I would gladly appreciate your help. Thanks.
Update:
First on a button click the word should then display. And many times I click the button I keep getting the same word again.
switch(v.getId()){
case R.id.btPlay:
randomWordList();
break;
}
Where randomWordList(); is the method I posted above.