Note that there are some explanatory texts on larger screens.

plurals
  1. POJava if statement is being ignored
    primarykey
    data
    text
    <p>I'm making a simple app where the user clicks a button which changes a TextView to the corresponding string, but when my first if statement is fulfilled it does not go on to fulfill the following if statement which should be.</p> <pre><code>if (index == 0 &amp;&amp; index &gt; -1 &amp;&amp; index &lt; 5) { one.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { index++; text1.setText("1"); } }); </code></pre> <p>This is my first if statement, it sets the TextView to "1", and then should add to the integer "index", this turns the index's value to "1", which should end this statement because it no longer qualify, which will begin the following if statement.</p> <pre><code>if (index == 1 &amp;&amp; index &gt; -1 &amp;&amp; index &lt; 5) { one.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { text2.setText("1"); index++; } }); </code></pre> <p>Now because of the previous <code>if</code> statement setting the index's variable to "1" this <code>if</code> statement should begin and the previous end, but this is not the case, even though the variables no longer qualify, it doesn't stop and the next if statement does not begin. It's as though the <code>if</code> statement is being ignored.</p> <p><strong>UPDATE.</strong></p> <p>I fixed my problem and here's what I changed the code to:</p> <pre><code>one.setOnClickListener(new View.OnClickListener(){public void onClick(View v){ if(index == 0){ text1.setText("1"); index++; }else if(index == 1){ text2.setText("1"); index++; }else if(index == 2){ text3.setText("1"); index++; }else if(index == 3){ text4.setText("1"); index++; } }}); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload