I want to insert an item (and even null) into a cursor at a particular index.
For example, I need to display 5 rows of information, but my query will get me a cursor with only 3 records, thus I need to display the other two columns (lets assume for the second and fourth rows) as "No information available". The view logic is already existing and it accepts a cursor and does the rest by checking the item at that index and will display "No information available" if null is found at that index. So now, when ever I have less than 5 records in my cursor, I must include the second and fourth index as null in it and should send the same to view.
But after some initial research found that there is no such way to insert to cursor at a particular index. Any one having any idea regarding this "updating the cursor manually"?
You cannot change the cursor (unless you create a MatrixCursor and copy the content - bad practice, anyway, as the cursor is really supposed to reflect data, not display details).
What you can do is modify you CursorAdapter like this :
/** Returns at least MIN_ITEM */
@Override
public int getCount() {
return Math.min(MIN_ITEM, super.getCount());
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (cursor.isAfterLast()) {
// Bind 'No information available' to your view
} else {
// Your current implementation
}
}