java - How to sort or reorder MergeCursor for ListViewAdapter -
i developing simple social media case study. able retrieve post people user follows. here's screenshot:
as can see, problem posts not sorted according date/id. instead, sorted according people user follows. because merging cursors using mergecursor. here's part of code:
listview listviewfeed = (listview) findviewbyid(r.id.listviewfeed); cursor cursorfeed = dataadapters.getfeed(dbhelper, struserid); //this code retrieving user's own posts cursor cursorfollowing = dataadapters.getfollowing(dbhelper,struserid); //this code retrieving followed users. if(cursorfollowing.getcount()>0) { (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 retrieving posts of people user follows. if(intctr>0) { mergecursor = new mergecursor(new cursor[]{mergecursor, cursorfollowingfeed}); }else { mergecursor = new mergecursor(new cursor[]{cursorfeed, cursorfollowingfeed}); } //this code merging 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 working well. want order posts date or id.
is there way sort mergecursor?
i guess there no way sort mergecursor tried think of other ways.
i changed query this:
public static cursor getfeed (dbhelper dbhelper, string struserid) { sqlitedatabase db = dbhelper.getreadabledatabase(); cursor cursorfollowing = getfollowing(dbhelper,struserid); string strquery = "select * feed_tbl "+ tables.feedtable.column_userid + "="+struserid; 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); string strconcatquery = " or "+ tables.feedtable.column_userid + "="+struseridi; if (intctr + 1 == cursorfollowing.getcount()) { cursorfollowing.close(); } else { cursorfollowing.movetonext(); } strquery = strquery +""+strconcatquery; log.v(tag,strquery); } } cursor cursor = db.rawquery(strquery+" order "+ tables.feedtable.column_id + " desc",null); if (cursor != null) { cursor.movetofirst(); } return cursor; }
the result on log tag this:
v/feedme: select * feed_tbl feed_userid=1 or feed_userid=2 or feed_userid=4 or feed_userid=5
just make things clear have same problem me mergecursor sorting. there no such way sort mergecursor :)
thankyou!
Comments
Post a Comment