How to sort or reorder MergeCursor for ListViewAdapter

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:

enter image description here

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(;
    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.

                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()) {
            } else {
        ListViewAdapterMeasurement adapterMeasurement = new ListViewAdapterMeasurement(this, mergeCursor);
        ListViewAdapterMeasurement adapterMeasurement = new ListViewAdapterMeasurement(this, cursorFeed);

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

Is there any way to sort MergeCursor?

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.