title: "if" and "else" with arraylist
body: <p>I am developing a game on Android studio.</p>
  
  <p>the game is 12 blocks and 12 symbols (in this case "0" zeros).
  When you press the new game button, the first level is initiated. there are 12 levels in total. (curLevel).
  For a few seconds, one symbol will be displayed randomly on the screen, and disappear. (according to each level the number of inputs increases 1, for example, Level 1 : 1 symbol has to be guessed, Level 2: 2 symbols has to be guessed) until level 12.</p>
  
  <p>Until this point, it is working with no problem.</p>
  
  <p>Now I need to solve my code to receive the user's input, check if matches with the right block previews showed. 
  If yes move to the next level(repeating the cycle of clearing the blocks, show random symbols, clearing again, waiting for the user's input) until level 12.
  If not show Fail message and Display new Game button again.</p>
  
  <p>I created this Arraylist but it's not working properly, Right now the condition it's always negative(even if the right block its pressed) the "Fail! Try Again!" message it is displaying.</p>
  
  <p>I ran the debugger and showed: List tempList = new ArrayList&lt;> (); </p>
  
  <pre><code>tempList:size 12
  for (int i = 0; i &lt; curLevel; i++) { curLevel size:13
  tempList.add ( buttons.get ( i ) ); buttons size:12
  if (tempList.contains ( v.getTag () )) { tempList size 12
  Its not matching the condition. –
  </code></pre>
  
  <p>here it is the values:</p>
  
  <pre><code>static int MAXLEVELS = 12;
          static String SUCCESS_SYMBOL = "0";
  curLevel = 1;
          curGuess = 0;
  </code></pre>
  
  <p>Any suggestion to make it work ? or even make this code tidier?</p>
  
  <pre><code>private void buttonLogic(View v) {
          List&lt;Button&gt; tempList = new ArrayList&lt;&gt; ();
          for (int i = 0; i &lt;= curLevel; i++) {
              if (i!= MAXLEVELS)
                  tempList.add ( buttons.get ( i ) );
              else
                  break;
          }
          if (tempList.contains ( v.getTag () )) {
              curGuess++;
              checkWin ();
          } else {
              lostGame ();
          }
      }
  
      private void lostGame () {
          Toast.makeText(this, "Fail! Try Again", Toast.LENGTH_SHORT).show();
          disableButtons();
          b_new.setVisibility(View.VISIBLE);
      }
  
          private void checkWin() {
              if (curGuess == curLevel) {
                  disableButtons ();
                  if (curLevel == 12) {
                      Toast.makeText ( this, "Congratulations! You Won", Toast.LENGTH_SHORT ).show ();
                      b_new.setVisibility ( View.VISIBLE );
                  } else {
                      curGuess = 0;
                      curLevel++;
                      generateButtons ( curLevel );
                  }
              }
          }
  </code></pre>
  
  <p>There is also an image from the previous code. Cheers.</p>
  
  <p><img src="https://i.stack.imgur.com/5H1Eh.jpg" alt="Here is the image"></p>