I have 4 buttons and an arraylist with numbers between 1-4, what I need to do is to compare the numbers in the array with the button I press (button 1, button 2, button 3, button 4) if it is correct to continue to the next number but call the next activity, I was trying and I can not do it.
pd: I use android studio.
@Override
public void onClick(View v) {
for (a = 0; a < list.size(); a++) {
switch (v.getId()) {
case R.id.b1:
p = 1;
break;
case R.id.b2:
p = 2;
break;
case R.id.b3:
p = 3;
break;
case R.id.b4:
p = 4;
break;
}
}
if (list.get(a) == p) {
iniciarTimer();
}
else{
encender=false;
fin();
}
}
That was the last thing I did, in the case that is b1 p = 1 and I compare with what I have in the list and the same with the other 3 buttons.
The idea of the program is that a random number is generated between 1 and 4, that button is lit and then I have to press that button, if it is correct a new one is generated and the first and the new button are lit, press those 2 buttons if it is correct another one is generated and it continues (it is the simon board game if they know it)
Edit: I leave the last thing I just did, the problem I have works fine until if, when I need to start the timer again (the timer starts after calling onClick
and when the onClick
ends call again to start timer)