title: Android - SimpleCursorAdapter changeCursor function too slow
body: <p>I am looking to find a solution to speeding up updating my spinners. Currently I am using a SimpleCursorAdapter and calling ChangeCursor whenever I change the search conditions based on the previously selected spinner.</p>
  
  <p>I did a bit of timing tests and the queries take from 5ms to 60ms, while the changeCursor function takes between 600ms and 4000ms+. Is there another method to updating the cursor on the adapter that is quicker? I am not using the same query, so I can't simply requery the cursor and then call notifydatasetchanged. I have to create a new query then get a new cursor back (maybe there is a better way to even do this portion).</p>
  
  <p>Here is how I am currently populating</p>
  
  <pre><code>private void writerSpinner() {
          String[] columns = new String[] { Passage.COL_WRITER_ID + " " + BaseColumns._ID, Passage.COL_WRITER_NAME };
          String whereClause = null;
          String groupBy = null;
          String orderBy = Passage.COL_WRITER_ID + " ASC";
  
          if (mAdapterPassage == null) {
              String[] columnsSpinner = new String[] { Passage.COL_WRITER_NAME };
              int[] to = new int[] { android.R.id.text1 };
  
              mAdapterPassage = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, null, columnsSpinner, to);
              mAdapterPassage.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              mPassage.setAdapter(mAdapterPassage);
              mPassage.setOnItemSelectedListener(onItemSelectedListener);
          }
  
          AsyncLoadData loadData = new AsyncLoadData(mAdapterPassage, mPassage, Passage.TABLE_NAME_WRITERS, columns, whereClause, groupBy, orderBy);
          loadData.execute();
      }
  
      private void updateChapterSpinner() {
          String[] columns = new String[] { Passage.COL_WRITER_ID + " " + BaseColumns._ID, Passage.COL_CHAPTER_ID };
          String whereClause = Passage.COL_WRITER_ID + " = " + mSelectedWriterId;
          String groupBy = Passage.COL_CHAPTER_ID;
          String orderBy = Passage.COL_CHAPTER_ID + " ASC";
  
          if (mAdapterChapter == null) {
              String[] columnsSpinner = new String[] { Passage.COL_CHAPTER_ID };
              int[] to = new int[] { android.R.id.text1 };
  
              mAdapterChapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, null, columnsSpinner, to);
              mAdapterChapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              mChapter.setAdapter(mAdapterChapter);
              mChapter.setOnItemSelectedListener(onItemSelectedListener);
          }
  
          AsyncLoadData loadData = new AsyncLoadData(mAdapterChapter, mChapter, Passage.TABLE_NAME_PASSAGES, columns, whereClause, groupBy, orderBy);
          loadData.execute();
      }
  
      private void updateVerseSpinner() {
          String[] columns = new String[] { Passage.COL_WRITER_ID + " " + BaseColumns._ID, Passage.COL_VERSE_ID };
          String whereClause = Passage.COL_WRITER_ID + " = " + mSelectedWriterId
                  + " AND " + Passage.COL_CHAPTER_ID + " = " + mSelectedChapter;
          String groupBy = Passage.COL_VERSE_ID;
          String orderBy = Passage.COL_VERSE_ID + " ASC";
  
  
          if (mAdapterVerse == null) {
              String[] columnsSpinner = new String[] { Passage.COL_VERSE_ID };
              int[] to = new int[] { android.R.id.text1 };
  
              mAdapterVerse = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, null, columnsSpinner, to);
              mAdapterVerse.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              mVerse.setAdapter(mAdapterVerse);
              mVerse.setOnItemSelectedListener(onItemSelectedListener);
          }
  
          AsyncLoadData loadData = new AsyncLoadData(mAdapterVerse, mVerse, Passage.TABLE_NAME_PASSAGES, columns, whereClause, groupBy, orderBy);
          loadData.execute();
      }
  
  private class AsyncLoadData extends AsyncTask&lt;Void, Void, Void&gt; {
          String mTableName; 
          String[] mColumns;
          String mWhereClause;
          String mGroupBy;
          String mOrderBy;
          Spinner mSpinner;
          Cursor mCursor;
          SimpleCursorAdapter mAdapter;
  
          public AsyncLoadData(SimpleCursorAdapter adapter, Spinner spinner, String tableName, String[] columns, String whereClause, String groupBy, String orderBy) {
              mAdapter = adapter;
              mSpinner = spinner;
              mTableName = tableName;
              mColumns = columns;
              mWhereClause = whereClause;
              mGroupBy = groupBy;
              mOrderBy = orderBy;
          }
  
  
          @Override
          protected void onPreExecute()
          {
              //mSpinner.setVisibility(View.GONE);
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              long startCursor = new Date().getTime();
              mCursor = mDBHandler.query(mTableName, mColumns, mWhereClause, null, mGroupBy, null, mOrderBy);
              long timeToQuery = new Date().getTime() - startCursor;          
  
              Log.i("CursorQuery", "Time to Query Cursor " + mGroupBy + ": "  + timeToQuery + "ms");
  
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result)
          {   
              long startAdapter = new Date().getTime();
              mAdapter.changeCursor(mCursor);
              long timeToChangeCursor = new Date().getTime() - startAdapter;
  
              Log.i("AdapterQuery", "Time to Change Cursor " + mGroupBy + ": " + timeToChangeCursor + "ms");
  
              mAdapter.notifyDataSetChanged();
              //mSpinner.setVisibility(View.VISIBLE);
          }
      }
  
  private OnItemSelectedListener onItemSelectedListener = new OnItemSelectedListener() {
  
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              switch(parent.getId()) {
              case R.id.bible_passage:
                  mSelectedWriterId = position + 1;
                  updateChapterSpinner();
                  break;
              case R.id.bible_chapter:
                  mSelectedChapter = position + 1;    
                  updateVerseSpinner();
                  break;
              case R.id.bible_verse:
                  mSelectedVerse = position + 1;
                  break;
              }
          }
  
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      };
  </code></pre>