title: Change Spinner based on another Spinner Selection
body: <p>I have string array which contains all the country names and another string array with respective country codes.
  I am setting the country names string to spinner.
  When I select the item from spinner its respective country code should be set to the spinner. And that item also should change to Code.
  Similarly if I select another item its code should be set to spinner and item too. But the first one I selected should change to its original country name.
  How should I do this?</p>
  
  <p>XML</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.temp.MainActivity" &gt;
  
  &lt;Spinner
      android:id="@+id/spinnerCountry"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="124dp" /&gt;
  
    &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Java Code</p>
  
  <pre><code>package com.example.temp;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.ArrayAdapter;
  import android.widget.Spinner;
  
  public class MainActivity extends Activity {
  
       final String[] countries = new String[] {"Afghanistan(AF)", "Albania(AX)",
                                                "Algeria(AL)", "American    Samoa(DZ)",
                                                "Andorra(AS)"};
  
      final String[] countrycodes = new String[]{"AF","AX","AL","DZ","AS"};
  
      Spinner spinnerCountry;
  
      ArrayAdapter&lt;String&gt; arrayAdapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          spinnerCountry=(Spinner)findViewById(R.id.spinnerCountry);
  
          arrayAdapter =  new ArrayAdapter&lt;String&gt;(getApplicationContext(), 
                                           android.R.layout.simple_list_item_1,countries);
          spinnerCountry.setAdapter(arrayAdapter);
      }
  }
  </code></pre>
  
  <p>I can't share my original as I am using it in my application.
  But, I am sharing the same code like my original one.
  I want to set respective code when I select country from spinner.</p>