【发布时间】:2017-12-16 22:58:03
【问题描述】:
我有一个从使用适配器显示的光标获取的 sqlite 数据填充的列表视图,我想在操作栏菜单单击时对列表视图进行排序,但光标似乎不像数组列表那样直接。
截取接收光标对象并在 onCreate() 中传递给适配器
databaseManager = new DatabaseManager(this);
databaseManager.open();
cursor = databaseManager.queryAllInsects();
swapCursor(cursor);
mAdapter = new InsectRecyclerAdapter(this, cursor);
bugsInsectRecyclerview.setAdapter(mAdapter);
在将调用菜单栏以触发刷新和排序的 optionsItemSelected() 中。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_sort_by_name:
// WHERE SORTING WOULD BE TRIGGERED tried querying the database again an passing sort order to a cursor seems not working
Cursor cursor2 = databaseManager.queryAllInsects(BugsContract.BugsEntry.COLUMN_FRIENDLYNAME);
swapCursor(cursor2);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
如何按字母顺序对从光标填充的列表视图进行排序?
【问题讨论】:
-
为什么不编写返回排序结果的查询?
-
ok 我将如何使查询刷新当前将数据填充到列表视图的游标,例如此方法 fethSortedData() 返回排序结果游标我将如何使用当前游标更改它菜单点击
标签: android arrays sorting colors