0
Everybody, Good afternoon.
I am wanting to compare 2 Array, where 1 array has randomly set value. I want to use for so I don’t have to repeat 100 times. But I don’t know, because it always shows me only the last value of the Array; Come on, I want it.
btQuestions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random randomico = new Random();
int perguntaaleatoria = randomico.nextInt(perguntas.length);
textQuestions.setText(perguntas[perguntaaleatoria]);
for(int i = 0;i < perguntas.length; i++) {
for (int j = i; j < respostas.length; j++) {
if (perguntas[i].equals(textQuestions.getText())) {
textoResposta.setText(respostas[j]);
}
}
}
at the moment it’s like this:
if (perguntas[1].equals(textQuestions.getText())) {
textoResposta.setText(respostas[1]);
}
if (perguntas[2].equals(textQuestions.getText())) {
textoResposta.setText(respostas[2]);
}
if (perguntas[3].equals(textQuestions.getText())) {
textoResposta.setText(respostas[3]);
In the second it does not present error, more imagine it with 100 questions! OO"
sbrubes, Good morning brother! You work with that? I wanted to have this reasoning, I thought I had to have the go, I still stayed about 5 minutes to understand what you did, which as I understood is not comparing the question and the answer, but rather taking the same random int to 2, thus setting both with the same value. Beat up a beat. kkk Brawl bro!! Really worth it.
– GuilDraco
It takes a long time. Stay firm, study and improve yourself! Anything we’re in, hug!
– sbrubes
Ai sbrubes, I tried to implement to use random question in any class, but then disfigured the comparison, I did so. public void onClick(View v) { textQuestions.setText(perguntas[numberAleatory()]); textoResposta.setText(respostas[numberAleatory()]); public int numberAleatory(){ Random randomico = new Random(); int perguntaaleatoria = randomico.nextInt(perguntas.length); return(perguntaaleatoria); Que fiz errado?
– GuilDraco
Dude.. Every time you call this function
numberAleatory
will generate a new random number, and then it won’t work at all. You should store this in a variable, but anything put a new question to make it clear to everyone. ;)– sbrubes
Brigadão bro, I recovered the value and then it worked, I had even done before. Fight even. You can close the topic as answered, I do not know how it does. Rsrs.
– GuilDraco