title: How to show Spinner-List when we tapped on button in android?
body: <p>Hi I recently came to the android technology and in my app I have two buttons(one for showing movies-list and another one for showing countrieslist)</p>
  
  <p>When I tap on the second button I want to display movies-list in spinner-list as in the first image bellow.</p>
  
  <p>But according to my code, when I tap on the button first spinner is appearing and I selected any one item and set that to my button title but after selection spinner still visible B/w two button as like my second screen how can remove it. </p>
  
  <p>How can I resolve this problem?</p>
  
  <p>Please help me. </p>
  
  <p>I want to show directly spinner-list when I tap on button. </p>
  
  <h2>xml:-</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:padding="10dp"
      android:id="@+id/parentLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:onClick="Button1Action"
          android:text="CountiesList"/&gt;
  
      &lt;Spinner
          android:visibility="gone"
          android:id="@+id/spinner1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/mainLayout"
          android:layout_alignParentRight="true"
          android:paddingRight="0dp"
          android:layout_marginTop="5dp"
          /&gt;
  
      &lt;Button
          android:id="@+id/button2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:onClick="Button2Action"
          android:text="MoviesList"/&gt;
  
      &lt;Spinner
          android:visibility="gone"
          android:id="@+id/spinner2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/mainLayout"
          android:layout_alignParentRight="true"
          android:paddingRight="0dp"
          android:layout_marginTop="5dp"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <h2>activity:-</h2>
  
  <pre><code>public class spinnerListProgramatically extends AppCompatActivity{
  
      String [] countriesList = {"india","usa","england"
      };
  
      String [] moviesList = {"fury","300 rise of an empire","troy"
      };
      Spinner spinner1,spinner2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.spinnerlist_runtime);
      }
  
      public void Button1Action(View view){
  
          spinner1  = (Spinner)findViewById(R.id.spinner1);
          ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, countriesList);
          dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner1.setAdapter(dataAdapter);
          spinner1.setVisibility(View.VISIBLE);
      }
  
      public void Button2Action(View view){
  
          spinner2  = (Spinner)findViewById(R.id.spinner2);
          ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, moviesList);
          dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner2.setAdapter(dataAdapter);
          spinner2.setVisibility(View.VISIBLE);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/8iqgp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8iqgp.png" alt="enter image description here"></a></p>
  
  <p>---<a href="https://i.stack.imgur.com/iRhWZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iRhWZ.png" alt="enter image description here"></a></p>