title: CursorAdapter: getCount() == 0, mCursor.getCount() == 6
body: <p>I have an adapter that wraps a <code>CursorAdapter</code>, the reason being that I need to display items in rows (as in a <code>GridView</code>) but also display detail about each item if clicked in a panel below (requiring a <code>ListView</code>).  So instead of a <code>CursorAdapter</code> directly populating the <code>ListView</code>, I have an inner adapter:</p>
  
  <pre><code>public class ChallengeAdapter extends BaseAdapter {
  
      class ChallengeDataAdapter extends CursorAdapter {
  
          private BaseAdapter mChallengeAdapter;
  
          public ChallengeDataAdapter(Context context, Cursor cursor, BaseAdapter a) {
              super(context, cursor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
              mChallengeAdapter = a;
          }
  
          @Override
          public void bindView(View arg0, Context arg1, Cursor arg2) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
              // TODO Auto-generated method stub
              return null;
          }
  
          @Override
          protected void onContentChanged() {
              super.onContentChanged();
              mChallengeAdapter.notifyDataSetChanged();
          }
  
      }
  
      private ChallengeDataAdapter mDataAdapter;
  
      public ChallengeAdapter(Context context, Cursor cursor) {
          mDataAdapter = new ChallengeDataAdapter(context, cursor, this);
      }
  
      @Override
      public int getCount() {
          return (mDataAdapter.getCount() + ChallengeMultiTile.ROW_SIZE - 1) / ChallengeMultiTile.ROW_SIZE; //integer divide rounds down
      }
  
      @Override
      public Object getItem(int position) {
          Challenge[] output = new Challenge[ChallengeMultiTile.ROW_SIZE];
          int min = position * ChallengeMultiTile.ROW_SIZE;
          int max = Math.min(position * ChallengeMultiTile.ROW_SIZE + ChallengeMultiTile.ROW_SIZE, mDataAdapter.getCount());
          for(int i=min; i&lt;max; ++i) {
              output[i-min] = Challenge.get((Cursor) mDataAdapter.getItem(i));
          }
          return output;
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          if(convertView==null) {
              convertView = new ChallengeMultiTile(parent.getContext());
          }
          ((ChallengeMultiTile) convertView).populate((Challenge[]) getItem(position));
          convertView.setBackgroundColor(0xfffffff);
          return convertView;
      }
  
      public void swapCursor(Cursor cursor) {
          mDataAdapter.swapCursor(cursor);
          notifyDataSetChanged();
      }
  
  }
  </code></pre>
  
  <p>This works briefly, but then the <code>ChallengeDataAdapter</code> starts to have a <code>getCount()</code> of zero.  However, I put a breakpoint there and <code>ChallengeDataAdapter#mCursor.getCount()</code> is 6.  I trapped this in the <code>onContentChanged()</code> method but I don't know for sure that's where it's happening.</p>
  
  <p>Why would a <code>CursorAdapter</code> give a count of zero when its inner cursor gives a count of six?</p>