jeudi 2 mai 2019

Is there an easy method or function to randomly select a string from an array string that was randomly selected from another array?

I'm new to java and android studio as a whole and was wondering if there was any way to basically nest 2 random functions.

I have string arrays in an XML file, and each string array is defined in my java file and added to another array.

What I have been attempting is to randomly select one of the string arrays from the first array, then from that selected string array to pick a string item randomly as well. I am also stuck on then getting just this string item from the string array to be placed in a predefined TextView.

Below is a snippet of my code where I want this to take place if possible.

Any suggestions or ideas would be much appreciated.

final String[][] planet = {Earth, Moon, Europa, etc...};
hint.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
        int randomIndex1 = new Random().nextInt(planet.length);
        String[] randomHint1 = planet[randomIndex1];
        hint1.setText(randomIndex1);}




Aucun commentaire:

Enregistrer un commentaire