android mergecursor 排序,java - How to sort or reorder MergeCursor for ListViewAdapter - Stack Overflo...

I am developing a simple social media for my case study. I was able to retrieve the post from the people the user follows. Here's the screenshot:

cIG2R.png

As you can see, the problem is that the posts were not sorted according to date/id. Instead, it is sorted according to the people the user follows. It is because I am only merging the cursors using mergecursor. Here's a part of my code:

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);

}

It is all working well. I just want to order the posts by Date or by ID.

Is there any way to sort MergeCursor?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值