title: Android updating a spinner based on "Parent" spinner's selection - .notifyDataSetChange() not firing?
body: <p>So, I have two spinners, let's call the first spinner Parent (account_type_spinner) and the second spinner Child (account_name_spinner). Please notice in the following code the ArrayAdapter initialization for the Child (account_name_spinner), I am feeding it a string array of account names I previously queried before the following lines of code (account_name_array):</p>
  
  <pre><code>//---define spinner objects as variables, assign adapters and listeners---
  
      account_type_spinner = (Spinner) findViewById(R.id.account_type_spinner);       
      account_type_adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, account_type_array);
      account_type_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      account_type_spinner.setAdapter(account_type_adapter);
      account_type_spinner.setOnItemSelectedListener(new SpinnerSelectionListener());
  
      account_name_spinner = (Spinner) findViewById(R.id.account_name_spinner);      
      account_name_adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, account_name_array);
      account_name_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      account_name_spinner.setAdapter(account_name_adapter);     
  </code></pre>
  
  <p>Selection in the Parent spinner triggers my "SpinnerSelectionListener" which is simply my class implementing OnItemSelectedListener. This class fires obviously each time a selection is made in the Parent spinner and the code looks like the following:</p>
  
  <pre><code>public class SpinnerSelectionListener implements OnItemSelectedListener {
  
      public void onItemSelected(AdapterView&lt;?&gt; parent,
          View view, int pos, long id) {          
          String spinner_selection = parent.getItemAtPosition(pos).toString();
  
          if(spinner_selection.contentEquals(INCOME)) {               
              //---grab Income type accounts from db and build array---               
              db.open();
              account_name_array = db.getAccounts(INCOME);    
              account_name_adapter.notifyDataSetChanged();
  
              dr_amount_textview.setVisibility(View.GONE);
              dr_amount.setVisibility(View.GONE);
              cr_amount_textview.setVisibility(View.VISIBLE);
              cr_amount.setVisibility(View.VISIBLE);
              db.close();
          } else {
              //---grab Expense type accounts from db and build array---
              db.open();
              account_name_array = db.getAccounts(EXPENSE);
              account_name_adapter.notifyDataSetChanged();
  
              cr_amount_textview.setVisibility(View.GONE);
              cr_amount.setVisibility(View.GONE);
              dr_amount_textview.setVisibility(View.VISIBLE);
              dr_amount.setVisibility(View.VISIBLE);
              db.close();
          }
      }
  
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
        // Do nothing.
      }
  }
  </code></pre>
  
  <p>The code above should update the Child (account_name_spinner) with INCOME or EXPENSE accounts whenever the Parent's selection changes from INCOME to EXPENSE or vice versa (this is an accounting app). The updating of the Child's spinner list should be facilitated by the "account_name_adapter.notifyDataSetChanged();" however nothing is happening.</p>
  
  <p>I looked into this issue further on StackOverflow and found that I must .clear() or .remove() items from my Child's ArrayAdapter (account_name_adapter) before the list will update, however, when I try "account_name_adapter.clear();" before notifying the ArrayAdapter I get an error that the operation is illegal. Any ideas what I am doing wrong? </p>