title: Android If condition
body: <p>In a android app, I click a button a flag is set to 1 and then I check if its set to 1 to do something. but its not working!</p>
  
  <pre><code>public class MainActivity extends Activity {
      Button button1;
      TextView text1;
      int flag=0;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);;
          text1 =(TextView) findViewById(R.id.text1);
          button1 = (Button) findViewById(R.id.button1);
          button1.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  flag = 1;
              }
          });
  
  
      if(flag == 1 ){
          text1.setText("Manoj Kumar S");
  
      }
  }
  </code></pre>
  
  <p>This logic doesn't seem to work! Why?</p>