title: if else statement in android
body: <p>I was new in Android and found some good tutorials on the internet, so I tried a simple activity with an <code>if-else</code> statement. I'm trying "correct and wrong" prompt/<code>Toast</code>:</p>
  
  <pre><code>Button page1 = (Button) findViewById(R.id.button2);
         page1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  final ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
                  if (iv1.equals(R.drawable.airplane1)) {
                      Toast.makeText(getApplicationContext(), "Correct",
                              Toast.LENGTH_SHORT).show();
                  } else if (iv1.equals(R.drawable.airplane2)) {
                      Toast.makeText(getApplicationContext(), "Please put an answer",
                              Toast.LENGTH_SHORT).show();
                  } else if (iv1.equals(R.drawable.airplane3)){
                      Toast.makeText(getApplicationContext(), "Wrong",
                              Toast.LENGTH_SHORT).show();
                  }
              }
  
         });
  </code></pre>
  
  <p>I'm not sure what is wrong in my <code>if-else</code> statement but never prompts at all. I tried removing the <code>(iv1.equals(R.drawable.airplane3))</code> and <code>(iv1.equals(R.drawable.airplane2))</code> then it only shows the wrong Toast. I can't get seem to make the correct to prompt me.</p>
  
  <p>Here is the full code of my class:</p>
  
  <pre><code>public class MainActivity extends Activity {
  private static final Random imagerandom = new Random();
  
  private static final Integer[] Imagesnumber = 
      { R.drawable.airplane1, R.drawable.airplane2, R.drawable.airplane3, };
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Integer a = Imagesnumber[imagerandom.nextInt(Imagesnumber.length)];
      final ImageView iv = (ImageView) findViewById(R.id.imageView1);
  
      View nextButton = findViewById(R.id.button1);
      nextButton.setOnClickListener(new Button.OnClickListener() {
           public void onClick(View V) {
                int resource = Imagesnumber[imagerandom.nextInt(Imagesnumber.length)];
                iv.setImageResource(resource);
           }
      });
      Button page1 = (Button) findViewById(R.id.button2);
         page1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  final ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
                  if (iv1.equals(R.drawable.airplane1)) {
                      Toast.makeText(getApplicationContext(), "Correct",
                              Toast.LENGTH_SHORT).show();
                  } else if (iv1.equals(R.drawable.airplane2)) {
                      Toast.makeText(getApplicationContext(), "Please put an answer",
                              Toast.LENGTH_SHORT).show();
                  } else if (iv1.equals(R.drawable.airplane3)){
                      Toast.makeText(getApplicationContext(), "Wrong",
                              Toast.LENGTH_SHORT).show();
                  }
              }
  
         });
  
  
  
  
  }
  
  }
  </code></pre>