我的数据库中有三个具有三个字符串属性的对象。其中一个显示日期信息,例如。 2016年4月1日,20.10.2017。我在ListView中列出这些对象,但在我想按日期排序之前。
//
//Show all Data on ListView
//
private void displayListView() {
Cursor cursor = datasource.fetchAllData();
// The desired columns to be bound
String[] columns = {
DatabaseHelper.COLUMN_TITLE,
DatabaseHelper.COLUMN_DESCRIPTION,
DatabaseHelper.COLUMN_DEADLINE,
};
// the XML defined views which the data will be bound to
int[] to = new int[] {
R.id.processobject_title,
R.id.processobject_description,
R.id.processobject_deadline,
};
// create the adapter using the cursor pointing to the desired data
//as well as the layout information
dataAdapter = new SimpleCursorAdapter(
this, R.layout.listview_viewlayout,
cursor,
columns,
to,
0);
ListView listView = (ListView) findViewById(R.id.listview);
ArrayList <ProcessObject> arrayList = new ArrayList<>();
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
activateAddButton();
OnItemClickListener();
};
我看到了两个问题:对光标进行排序,或者将数组排序为[]。但我不知道如何。
public Cursor fetchAllData(){
Cursor cursor = database.query(DatabaseHelper.TABLE_DATABASE, columns, null, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
答案 0 :(得分:0)
解决了它:
String orderBy = DatabaseHelper.COLUMN_DEADLINE + " ASC";;
Cursor cursor = database.query(DatabaseHelper.TABLE_DATABASE, columns, null, null, null, null, orderBy);