I am currently trying to make an order game. The user had to press the buttons in the order given. How ever I am having some problem with the else statement. This is my code.
private OnClickListener click2 = new OnClickListener() { List<Integer> mClickedButtonIds = new ArrayList<Integer>(); @Override public void onClick(View v) { mClickedButtonIds.add(v.getId()); if (mClickedButtonIds.size() > 4 ) { mClickedButtonIds.remove(0); int[] mDesiredOrder = new int[] { R.id.imageButton1, R.id.imageButton2, R.id.imageButton3, R.id.imageButton4 }; if (mClickedButtonIds.get(0) == mDesiredOrder[0] && mClickedButtonIds.get(1) == mDesiredOrder[1] && mClickedButtonIds.get(2) == mDesiredOrder[2] && mClickedButtonIds.get(3) == mDesiredOrder[3] ) { tv1.setText("Correct"); } else { tv1.setText("Wrong"); } } } }; If I play the game for the first time, the else statement work perfectly. But if I play the game again without closing the application, the else statement start to have problem. Every single button I press will come out the else statement which make my tv1 to set text as Wrong. But the ifstatement still work perfectly. Means that although it keep on set text as Wrong but if I click the final button of the correct order it will set text as Correct. Is there any solution for this?
private OnClickListener click2 = new OnClickListener() { List<Integer> mClickedButtonIds = new ArrayList<Integer>();do this in onResume(), not onCreate().