I want to make an English word game based on the game of catching a mole. First of all, catching a mole has been solved, but I have to put English words into this game, but it's blocked from here; English words are prepared. But I didn't know how to put it in;
I'd appreciate it if you could tell me which function to use and whether to put it in the java file or the xml file;
android android-studio
First of all, place the TextView properly so that English words can be seen on the screen. Then, if English words should be exposed randomly, implement it so that English words can be imported randomly into Java code.
The simplest code is to put the English word in the list and mix the list using the Collections.shuffle() function. Please refer to the following code and results and print out English words in TextView.
List<String> words = new ArrayList<String>() {{
add("activity"); add("service"); add("intent");
add("context"); add("view"); add("widget");
add("toolbar"); add("toast"); add("anr");
}};
Collections.shuffle(words);
// Output for result verification
System.out.print(Arrays.toString(words.toArray(new String[words.size()])));
At runtime, you can see that the order of the list is output differently each time.
First run [toolbar, service, context, int, activity, view, toast, widget, anr]
Second run [int, activity, toast, toolbar, widget, view, anr, context, service]
Third run [toolbar, toast, service, int, widget, activity, anr, view, context]
Fourth execution [widget, activity, toast, service, context, view, toolbar, anr, int]
...
...
© 2024 OneMinuteCode. All rights reserved.