我使用ListView
来显示记录的历史记录。我使用数据库来存储记录并将其拉入ListView
。现在,我想通过这样做再次拉出这条记录:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
positions = position;
checkdata();
}
}
使用位置从数据库中获取数据并转换为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);
}
当我对ListView
进行反向排序时,问题就开始了,因为ListView
会在顶部显示所有最近的记录,而在底部使用旧的记录在适配器中显示它用户。
Collections.reverse(records);
如何以相反的顺序获得位置(id)?
答案 0 :(得分:0)
你有很多选择 选项1:您可以根据一列
反转查询顺序 Cursor cursor= sqLiteDatabase.query("record", columns, null, null, null, null yourColumn+" DESC");
选项2:如果您在ArrayList数据结构上发送数据,则可以将其反转
Collections.reverse(YourList);
选项3:您可以自行反转ListView,但这不适用于您的问题
android:stackFromBottom="true"
android:transcriptMode="normal"