title: Always Selecting the Else Statement in Spinner
body: <p>I am trying to set the text of textView according to the item selected in the spinner. But it is always showing the value of the else statement. Can someone please help me in solving this.
  The code is given below.</p>
  
  <pre><code>import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.ArrayAdapter;
  import android.widget.Spinner;
  import android.widget.SpinnerAdapter;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          String[] names = {"Shashank","Abhijay"};
          String[] state_array = {"Select City","Bangalore","Jaipur"};
          setContentView(R.layout.activity_main);
          Spinner spinner_state = (Spinner)findViewById(R.id.spinner1);
          spinner_state.setAdapter((SpinnerAdapter) new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_list_item_1,
                      state_array ));
  
          if(spinner_state.equals(state_array[1]))
          {
          TextView candi_name = (TextView) findViewById(R.id.CandidateName);
          candi_name.setText(names[0]);
          }
          if(spinner_state.equals(state_array[2])){
              TextView candi_name = (TextView) findViewById(R.id.CandidateName);
              candi_name.setText(names[1]);
          }
          else{
              TextView candi_name = (TextView) findViewById(R.id.CandidateName);
              candi_name.setText(" ");
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>