Beker
Beker

Reputation: 1

add text to buttons randomly android studio

as I can add those buttons at random name to start a different name on a button

public static String[] warriors={"tan","android16","andsaroid17","goku","bardock","bills","boo"};

Upvotes: 0

Views: 243

Answers (1)

Wilik
Wilik

Reputation: 7720

You can random a number from 0 to the length of the array of String and then set the text to the button.

Random rand = new Random();
int random_number = rand.nextInt(warriors.length);

button.setText(warriors[random_number]);

Hope this helps :)

Upvotes: 1

Related Questions