How to sort the CursorLoader results?

前端 未结 4 1490
走了就别回头了
走了就别回头了 2021-01-05 07:04

I use CursorLoader to query a result, which is not the order that I want to show in the ListFramgenet. How to sort it ?

I use this to set the adapter:



        
4条回答
  •  日久生厌
    2021-01-05 07:47

    What you're looking for is supplying a sortOrder argument something like the following:

    (the ORDER BY at the start of this is implicait and you do not include it, simply included here for clarity)

    ORDER BY 6366000*acos(cos(lat_a / (180/3.14169))*cos(lng_a / (180/3.14169))*cos(lat_b / (180/3.14169))*cos(lng_b / (180/3.14169)) + t2 + t3) ASC
    

    (for this I took the answer here and inlined it - except I didn't bother with t2 and t3, because it's not going to work anyway)

    Unfortunately, this is impossible in standard SQLite - there are no operators sin, or cos - or even a square root or power operator (after seeing your comment about only requiring a more simple calculation).

    You can add your own functions, but that's a somewhat more complicated route.

    Depending on how many rows you have, you might be alright to just read them all and then sort them yourself.

提交回复
热议问题