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. 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);
//List with the riddles and its values
HashMap<String, String> h = new Hashmap<String, String>();
h.put("a", "v");
h.put("b", "w");
h.put("c", "x");
h.put("d", "y");
h.put("e", "z");
//rand generator for array
String[] yourKeyList = h.keySet().toArray(new String[]{});
String[] yourValueList = h.values().toArray(new String[]{});
String randomKey = yourKeyList[new Random().nextInt(yourKeyList.length)];
final String keyValue = yourValueList[yourValueList.length];
answerTxt.setText(randomKey);
answerTxt.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
answerTxt.setText(keyValue);
return true;
}
});