I use a ListView
to show a history of a record. I use database in order to store and pull the record into the ListView
. Now, I want to pull this record again by doing this:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
positions = position;
checkdata();
}
}
and get the data from the database using the positions and turning into id
public void checkdata() {
String[] columns = {"id", "titleexam", "address", "time", "score", "Examdata", "totalscore", "hour", "min", "sec", "timedis"};
Cursor cursor = sqLiteDatabase.query("record", columns, null, null, null, null, null);
cursor.move(positions);
ExamRecord recordr = new ExamRecord(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getString(7), cursor.getString(8), cursor.getString(9), cursor.getString(10));
title = cursor.getString(1);
data = cursor.getString(5);
}
The problem begin when I sort the ListView
in reverse, because the ListView
will show all the recent record at the top and the older ones at the bottom using this in the adapter to show it at the user.
Collections.reverse(records);
How can I get the position(id) on the reverse order?