Very interesting problem. I have a ListView with a custom CursorAdapter. When creating an adapter, I give it 2 cursors:

Cursor structure = SQLD.query("Structure", new String[]{"_id", "NumNote", "Type"}, "DATE = "+Date, null, null, null, null, null); Cursor texts = SQLD.query("Texts", new String[] {"_id", "NumNote", "Text"}, "DATE = "+Date, null, null, null, null, null); CustomCursorAdapter CCA = new CustomCursorAdapter(this, structure, texts); 

The Structure table looks like this: Table structure

Next in the constructor, I call the superclass constructor and pass it the structure cursor:

 public CustomCursorAdapter(Context context, Cursor structure, Cursor inTexts) { super(context, structure, 0); 

That is, this cursor will be passed to the newView and bindView methods. And now if we check the content of the cursor in any of these methods, then the 3rd line will be thrown:

 @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { while(cursor.moveToNext()){ Log.i("CursorAdapter", cursor.getInt(cursor.getColumnIndex("NumNote"))+" "+ cursor.getString(cursor.getColumnIndex("Type"))); } 

Logcat output:

 I/CursorAdapter: 0 Text I/CursorAdapter: 0 Text I/CursorAdapter: 1 Text I/CursorAdapter: 1 Text I/CursorAdapter: 2 Text 

And if you check the cursor that passed to the constructor with a custom adapter, then everything is fine, I'm in a stupor.

  • Why do you think that the third line is missing? I think that the first is missing and this is due to the initial positioning of the cursor. Upon receipt, the cursor pointer is in front of the first line and to retrieve data, it must be set to the beginning, and then iterate further - pavlofff
  • you create Cursor texts, and then in the constructor you work with Cursor inTexts, is it a coincidence or an idea like that? - ZigZag
  • @ZigZag, yes, an idea, well, more precisely an unsuccessful name :) - R. Bes
  • @pavlofff, yes, the first line is really lost and this is connected with the initial positioning, only when it is received, the cursor pointer is already on the first line, therefore it is unnecessary to set it to the beginning. Thanks for the answer :) - R. Bes

1 answer 1

Indeed, you are missing not the third, but the first line. You can make sure you simply output the id to the log.
Before the first iteration, you need to do cursor.moveToFirst()

  • indeed, the first record is lost without movetofirst, a very strange behavior, as for me, thanks for the answer - R. Bes
  • well, everything became clear, when receiving a pointer from the cursor is already in the first place, so calling the movetofirst is superfluous. I will simply continue to use the cycle with a postcondition - R. Bes