title: Android spinner don't show selected text while list appears in drop down
body: <p>i am newbie in android and i am trying to use two spinner views in an activity. entries are showing in drop down of spinner but when i select an entry, it doesn't appear in spinner control. I have searched all over but it didn't work for me. following is all i am doing/trying.
  My activity xml is as </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/activity_seventy_thirty"
      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.elecsysindia.montestapp.SeventyThirtyActivity"&gt;
  
      &lt;TextView
          android:text="Division"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/txtDivison"
          android:textSize="20sp"
          android:layout_alignParentTop="true"
          android:layout_marginTop="16dp"
          android:layout_marginRight="16dp"
          /&gt;
  
      &lt;Spinner
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/spinnerDivision"
          android:layout_marginLeft="32dp"
          android:layout_alignTop="@+id/txtDivison"
          android:layout_toRightOf="@+id/txtDivison"
          android:layout_toEndOf="@+id/txtDivison" /&gt;
      &lt;TextView
          android:text="Station"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/txtDivison"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="16dp"
          android:layout_marginRight="16dp"
          android:id="@+id/txtStationCode"
          android:textSize="20sp" 
          /&gt;
      &lt;Spinner
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/spinnerStation"
          android:layout_below="@+id/spinnerDivision"
          android:layout_alignLeft="@+id/spinnerDivision"
          android:layout_alignStart="@+id/spinnerDivision"
          android:layout_marginTop="16dp"
          android:layout_marginStart="48dp"
          android:layout_marginBottom="16dp"
          android:layout_marginLeft="48dp" /&gt;
      &lt;Button
          android:text="Submit"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/btnSubmit"
          android:layout_marginLeft="16dp"
          android:layout_marginTop="16dp"
          android:layout_alignLeft="@+id/spinnerStation"
          android:layout_below="@+id/spinnerStation"
          /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and in class:</p>
  
  <pre><code>private static List&lt;String&gt; listDivisions = new ArrayList&lt;String&gt;();
  private List&lt;String&gt;  listStation = new ArrayList&lt;&gt;();
  Spinner spinnerDivision ;
  Spinner spinnerStation;
  Button btnSubmit;
  ArrayAdapter&lt;String&gt; adapterDivision;
  ArrayAdapter&lt;String&gt; adapterStation;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_seventy_thirty);
      spinnerDivision = (Spinner) findViewById(R.id.spinnerDivision);
      spinnerStation = (Spinner) findViewById(R.id.spinnerStation);
      btnSubmit = (Button) findViewById(R.id.btnSubmit);
     // adapterDivision = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item,listDivisions);
      adapterDivision = new ArrayAdapter&lt;String&gt;(getApplicationContext(),R.layout.layout_spinner_item,listDivisions);
  
      adapterDivision.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinnerDivision.setAdapter(adapterDivision);
      adapterDivision.notifyDataSetChanged();
  
      adapterStation = new ArrayAdapter&lt;String&gt;(getApplicationContext(), android.R.layout.simple_spinner_item,listStation);
      adapterStation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinnerStation.setAdapter(adapterStation);
      adapterStation.notifyDataSetChanged();
  </code></pre>
  
  <p>And this is how lists are updated:</p>
  
  <pre><code>for (int i = 0; i &lt; subs.length(); i++){
                      JSONObject subsDetail = subs.getJSONObject(i);
                      ArrayList&lt;String&gt; stnList = new ArrayList&lt;String&gt;();
                      if(subsDetail != null){
                          stnList.clear();
                          String DivCode = subsDetail.getString("divCode");
                          JSONArray st = subsDetail.getJSONArray("stncode");
                          String city="";
                          for (int j=0 ; j&lt;st.length(); j++){
                              stnList.add(st.getString(j));
                              city = city.concat(st.getString(j)+"-");
                          }
                          mapSubscriptions.put(DivCode,stnList);
                          listDivisions.add(DivCode);
                          listStation.addAll(stnList);
  </code></pre>
  
  <p>I am getting data from simple php script and this data is getting inserted to lists.</p>
  
  <p>Also after searching related issue in Sof, i have tried to use a separate layout for spinner as used in </p>
  
  <pre><code>adapterDivision = new ArrayAdapter&lt;String&gt;(getApplicationContext(),R.layout.layout_spinner_item,listDivisions);
  </code></pre>
  
  <p>but still of no use. 
  xml file for layout_spinner_item is as follows:</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/spinnerItem"
      android:textSize="20sp"
      android:gravity="left"
      android:textColor="#aaddaa"
      android:padding="5dip"
      /&gt;
  </code></pre>
  
  <p>I even tried to make text color change in theme itself by setting property android:textColor. but again no success.</p>
  
  <pre><code>&lt;item name="android:textColor"&gt;#FF00FF&lt;/item&gt;
  </code></pre>
  
  <p>can you please help me why text is not appearing in spinner control.</p>
  
  <p>After a lot of struggle, text in one spinner is appearing but that appears only if i restart activity directly , i mean without navigating to activity from main activity. 
  second spinner (spinnerStation) dont show the text at all. even same source code for both spinners. please see screen shots.
  <a href="https://i.stack.imgur.com/oVJdn.png" rel="nofollow noreferrer">text appear in spinnerDivision</a></p>
  
  <p><a href="https://i.stack.imgur.com/vZ4gw.png" rel="nofollow noreferrer">Entries of spinnerStation which dont show text</a></p>