title: How to reset spinner list when fragment resume?
body: <p>I have two spinner in my application which populating list from sqlite and it is working fine. When I select State in first spinner then second spinner list populate depend on first spinner. Now what I want that when I select item in both spinner and then I press back and again launch the activity then the list of second spinner still there. I want to clear list of second spinner when I press back button and Populate list in second spinner when user select value in first spinner.</p>
  
  <pre><code>public void fillStateData() {
          try {
              ArrayList&lt;String&gt; state_array = new ArrayList&lt;String&gt;();
              state_array.add("Select State");
              Cursor cursor_State = db.rawQuery("SELECT nSerialNo as _id,cCodeName FROM CodeMaster where nCtgId = 6", null);
  
  
              if (cursor_State.moveToFirst()) {
                  do {
                      //assing values
                      String stateID = cursor_State.getString(0);
                      String stateName = cursor_State.getString(1);
                      stateData = stateName;
                      state_array.add(stateData);
                  } while (cursor_State.moveToNext());
              }
              ArrayAdapter my_Adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, state_array);
              spnState.setAdapter(my_Adapter);
              cursor_State.close();
              spnState.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                  @Override
                  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
                      state = spnState.getSelectedItem().toString();
  
                      Cursor cursor = db.rawQuery("SELECT nSerialNo FROM CodeMaster where cCodeName = '" + state + "'", null);
  
                      if (cursor.moveToFirst()) {
                          stateCodeId = cursor.getString(0);
                      }
                      cursor.close();
  
                      fillDistrictData(stateCodeId);
                  }
  
                  @Override
                  public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
                  }
              });
          } catch (Exception e) {
  
              e.printStackTrace();
  
          }
      }
  
      public void fillDistrictData(String stateCodeId) {
          try {
              district_array = new ArrayList&lt;String&gt;();
              district_array.clear();
              district_array.add("Select District");
              Cursor cursor_District = db.rawQuery("SELECT nSerialNo as _id,cCodeName FROM CodeMaster where nParentSerialNo = '" + stateCodeId + "'", null);
  
  
              if (cursor_District.moveToFirst()) {
                  do {
                      //assing values
                      String districtID = cursor_District.getString(0);
                      String districtName = cursor_District.getString(1);
                      districtData = districtName;
                      district_array.add(districtData);
  
  
                  } while (cursor_District.moveToNext());
              }
              district_Adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, district_array);
              spnDistrict.setAdapter(district_Adapter);
              cursor_District.close();
              spnDistrict.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                  @Override
                  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
                      district = spnDistrict.getSelectedItem().toString();
  
                      Cursor cursor = db.rawQuery("SELECT nSerialNo FROM CodeMaster where cCodeName = '" + district + "'", null);
  
                      if (cursor.moveToFirst()) {
                          do {
                              //assing values
                              districtCodeId = cursor.getString(0);
  
                          } while (cursor.moveToNext());
                      }
                      cursor.close();
  
                      fillTalukaData(districtCodeId);
  
                  }
  
                  @Override
                  public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
                  }
  
  
              });
          } catch (Exception e) {
  
              e.printStackTrace();
  
          }
  
      }
  </code></pre>