title: Swapping of Spinners
body: <p>My app consists of two spinners and one button, i have selected each value from each spinner, later i had swapped the spinner adapters using button click, when spinner adapters are modified, the result by default represents initial values, no matter what ever values i have given.</p>
  <p>This is how my <strong>MainActivity</strong> looks like</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private Spinner alphabets, numbers;
  private Button swapSpinners;
  private ArrayAdapter&lt;CharSequence&gt; alphabetsAdapter, numbersAdapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      alphabets = (Spinner) findViewById(R.id.alphabets);
      numbers = (Spinner) findViewById(R.id.numbers);
      swapSpinners = (Button) findViewById(R.id.swapSpinner);
  
  
      alphabetsAdapter = ArrayAdapter.createFromResource(this,
              R.array.alphabets, android.R.layout.simple_spinner_item);
      alphabetsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      alphabets.setAdapter(alphabetsAdapter);
  
      numbersAdapter = ArrayAdapter.createFromResource(this,
              R.array.numbers, android.R.layout.simple_spinner_item);
      numbersAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      numbers.setAdapter(numbersAdapter);
  
      swapSpinners.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if (alphabets.getAdapter().equals(alphabetsAdapter)) {
                  alphabets.setAdapter(numbersAdapter);
                  numbers.setAdapter(alphabetsAdapter);
              } else {
                  alphabets.setAdapter(alphabetsAdapter);
                  numbers.setAdapter(numbersAdapter);
              }
          }
      });}
  }
  </code></pre>
  <p>This is how my <strong>activity_main</strong> looks like</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
   &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  android:paddingBottom=&quot;@dimen/activity_vertical_margin&quot;
  android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;
  android:paddingRight=&quot;@dimen/activity_horizontal_margin&quot;
  android:paddingTop=&quot;@dimen/activity_vertical_margin&quot;
  tools:context=&quot;karthik.spinnerswap.MainActivity&quot;&gt;
  
  &lt;Spinner
      android:id=&quot;@+id/alphabets&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot; /&gt;
  &lt;Button
      android:id=&quot;@+id/swapSpinner&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_below=&quot;@+id/alphabets&quot;
      android:text=&quot;Swap Spinners&quot; /&gt;
  &lt;Spinner
      android:id=&quot;@+id/numbers&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_below=&quot;@id/swapSpinner&quot; /&gt;
    &lt;/RelativeLayout&gt;
  </code></pre>
  <p>This is how my <strong>strings.xml</strong> looks like</p>
  <pre><code>&lt;resources&gt;
  &lt;string name=&quot;app_name&quot;&gt;SpinnerSwap&lt;/string&gt;
  
  &lt;string-array name=&quot;alphabets&quot;&gt;
      &lt;item&gt;A&lt;/item&gt;
      &lt;item&gt;B&lt;/item&gt;
      &lt;item&gt;C&lt;/item&gt;
      &lt;item&gt;D&lt;/item&gt;
      &lt;item&gt;E&lt;/item&gt;
      &lt;item&gt;F&lt;/item&gt;
      &lt;item&gt;G&lt;/item&gt;
      &lt;item&gt;H&lt;/item&gt;
      &lt;item&gt;I&lt;/item&gt;
      &lt;item&gt;J&lt;/item&gt;
  &lt;/string-array&gt;
  
  &lt;string-array name=&quot;numbers&quot;&gt;
      &lt;item&gt;0&lt;/item&gt;
      &lt;item&gt;1&lt;/item&gt;
      &lt;item&gt;2&lt;/item&gt;
      &lt;item&gt;3&lt;/item&gt;
      &lt;item&gt;4&lt;/item&gt;
      &lt;item&gt;5&lt;/item&gt;
      &lt;item&gt;6&lt;/item&gt;
      &lt;item&gt;7&lt;/item&gt;
      &lt;item&gt;8&lt;/item&gt;
      &lt;item&gt;9&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  
  <p>Selecting values, <strong>before swapping</strong> the spinners
  <a href="https://i.stack.imgur.com/txjEI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/txjEI.png" alt="before swapping" /></a></p>
  <p>spinners <strong>after swapping</strong>
  <a href="https://i.stack.imgur.com/yQ43h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yQ43h.png" alt="after swapping" /></a></p>
  <p>I need to show the <strong>selected values</strong> after <strong>swapping the spinners</strong></p>