samedi 8 juillet 2017

How to match correct answers in a randomly generated array in Android?

So I'm creating a riddle app that when you swipe up on the screen it will come up with a riddle that is randomly generated using an array. Now I have no idea which riddle will pop up because of course, it's random but I want the user to be able to click and hold on the randomly generated riddle and the answer will then pop up replacing the riddle. So far I have the array done to where it will randomly generate a riddle but I'm having a problem getting the answer to match up with riddles because of course they are random too. How would I go about matching correct answers to a random array on a long press of the text view?

I did see two other questions (one,two) and similar to this one but it did not answer the question that I have and it really wasn't specific.

final TextView answerTxt = (TextView) 
findViewById(R.id.answerTxt);


    final String[] riddles = {

            "No man is an island.",
            "Keep your friends close and your enemies closer.",
            "Never look a gift horse in the mouth.",
            "A watched pot never boils."

    };


    //random generator for user fortune
    final int random = (int) (Math.random() * riddles.length);
    answerTxt.setText(riddles[random]);




Aucun commentaire:

Enregistrer un commentaire