0
我正在爲我的案例研究開發一個簡單的社交媒體。我能夠從用戶關注的人員中檢索帖子。下面是截圖:如何對ListViewAdapter的MergeCursor進行排序或重新排序
正如你所看到的,問題是,職位沒有按照日期/編號的順序排列。相反,它是根據用戶關注的人進行分類的。這是因爲我只使用mergecursor合併遊標。以下是我的部分代碼:
ListView listviewFeed = (ListView) findViewById(R.id.listviewFeed);
Cursor cursorFeed = DataAdapters.getFeed(dbHelper, strUserID);
//This code is for retrieving user's own posts
Cursor cursorFollowing = DataAdapters.getFollowing(dbHelper,strUserID);
//This code is for retrieving the followed users.
if(cursorFollowing.getCount()>0) {
for (int intCtr = 0; intCtr < cursorFollowing.getCount(); intCtr++) {
int intUseridI = cursorFollowing.getColumnIndex(Tables.FollowTable.COLUMN_USERID);
String strUseridI = cursorFollowing.getString(intUseridI);
Cursor cursorFollowingFeed = DataAdapters.getFeed(dbHelper, strUseridI);
\\This code is for retrieving the posts of the people the user follows.
if(intCtr>0)
{
mergeCursor = new MergeCursor(new Cursor[]{mergeCursor, cursorFollowingFeed});
}else {
mergeCursor = new MergeCursor(new Cursor[]{cursorFeed, cursorFollowingFeed});
}
//This code is for merging the cursors.
if (intCtr + 1 == cursorFollowing.getCount()) {
cursorFollowing.close();
} else {
cursorFollowing.moveToNext();
}
}
ListViewAdapterMeasurement adapterMeasurement = new ListViewAdapterMeasurement(this, mergeCursor);
listviewFeed.setAdapter(adapterMeasurement);
}else
{
ListViewAdapterMeasurement adapterMeasurement = new ListViewAdapterMeasurement(this, cursorFeed);
listviewFeed.setAdapter(adapterMeasurement);
}
這一切都很好。我只想按日期或ID排列帖子。
有什麼辦法可以對MergeCursor進行排序嗎?
不要使用MergeCursor ...添加'getAllFollowingFeeds'並使用INNER JOIN那裏 – Selvin
謝謝你的回答:)我已經設法解決了我的問題,你給了我一個想法來改變我的查詢:) @Selvin –