Question

I have created a ListView with its value from the CursorAdapter .I am Successfully able to append the value to the Bottom of the List.

Now , How would I append the Value to ListView from top position

I know if I use ArrayAdapter or BaseAdapter I could b possible using add(postion , adapter) easily.

I want to know how could we do it using CursorAdapter.

Was it helpful?

Solution

A CursorAdapter just links the ListView with the Database/Data from the Database specified in the Cursors sqlQuery.

String sqlQuery = "Select * From WhatSoEver";

Cursor c = dbhelper.rawQuery(sqlQuery, null);

the list will get each Item/Row that the Cursor could find, matching the sql selection. So if you want to add another item, you have to add it to your database. If you dont specify any Order, it will be ordered by id or the order the rows were inserted.

If you want the latest items to show up first, you will have to specify a different order, assuming your table has an id, you could do it like this

String sqlQuery = "Select * From WhatSoEver Order By id desc";
Cursor c = dbhelper.rawQuery(sqlQuery, null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top