There is SQL in which, suppose, 500 lines. I'm using the query

 Cursor cursor = db.query(MESSAGES_TABLE, projection, selection, selectionArgs, null, null, sortOrder, howManyShow); 

where selection , selectionArgs - selectionArgs conditions (for example, " channel = ? ", "67822" - display messages only with the field channel = 67822 ) database and pass to the cursor only 30)

Accordingly, in the cursor we get 30 messages, starting from the 500th. But I need to fill my ListFragment with this cursor in the reverse order, so that the "500th" message is at the bottom of the List . Is there any option how to change the request so that the same 30 messages are displayed in the cursor in the reverse order (the "500th" message last ").

The number of rows in the database is not static. Also, the method of sending 2 requests will not work because the cursor will then not be updated correctly.

ListFragment filled with its own adapter inherited from SimpleCursorAdapter . If the request cannot be changed to fit my wishes, there may be ways to change the order of filling the List using the adapter 'a methods. Search in Google says that you need to change the request, but I don’t think how to change it correctly.

    1 answer 1

    The ideal solution would be to fetch just one request order by id desc limit 30 with the subsequent placement of data into an array. Then, under the conditions, you are already displaying an array of data in direct or reverse order, if the new ones are on top - you do not touch the array, if below, you simply reverse the array and output. type:

     if (new_msg on top) { так и показывать } else { перевернуть массив и показывать } 

    ps program on rnr (look for the analog rn function of array_reverse () for android)

    pps sc2tv)