Hello stackoverflow community, I have a problem in Android especially with SQLite. I've created an App where you can create a ToDo List. I work in this app with a ContentResolver and the list is displayed in a simple ListView. Actual Layout. The List is orderd with through the Cursor LoaderManager and has a ascending order. The projection is the following:
String[] projection = {
ToDoContract._ID,
ToDoContract.COLUMN_IMAGE,
ToDoContract.COLUMN_HEADLINE,
ToDoContract.COLUMN_DESCRIPTION,
ToDoContract.COLUMN_PRIORITY,
ToDoContract.COLUMN_WEEKDAY,
ToDoContract.COLUMN_DONE
};
String sortOrder = ToDoContract.COLUMN_WEEKDAY + " ASC";
The Weekdays are integers(1=monday, 7=sunday) because i didn't know another way to sort the weekdays.
My Problem is the following: I want to delete or edit these entries and i don't know how to get the row number of the entry. The ListView is registered for a ContextMenu. Here is an example: I get the ContextMenu position with the following code:
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
Now I have the position inside the ListView but i need the position in the sqlite database. My normal way was that i create a Uri with an appended ID
Uri currentListUri = ContentUris.withAppendedId(ToDoContract.CONTENT_URI, index);
But since my list is ordered, the way doesn't work. The ID in SQLite might be 4 and in my ListView it's 1. Has anybody a hint how to get the ordered position?
Edit:
Just make it clear, i already get the count of my database through this method:
TableDBHelper dbHelper = new TableDBHelper(getContext());
long count = dbHelper.getTodoCount();
And getTodoCount(); is the following:
public long getTodoCount() {
SQLiteDatabase db = this.getReadableDatabase();
long count = DatabaseUtils.queryNumEntries(db, ToDoContract.TABLE_NAME);
db.close();
return count;
}