0

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?

Izzuddin667
  • 83
  • 10

1 Answers1

0

you have many options
option 1: you can reverse query order based on one column

 Cursor cursor= sqLiteDatabase.query("record", columns, null, null, null, null yourColumn+" DESC");

option 2: if you send data on ArrayList data structure you can reverse it
Collections.reverse(YourList);

option 3: you can reverse ListView it self i don't it will work for your question

android:stackFromBottom="true"
android:transcriptMode="normal"
nima moradi
  • 2,300
  • 21
  • 34