Display posts in descending posted order

前端 未结 18 913
南方客
南方客 2020-11-22 11:47

I\'m trying to test out Firebase to allow users to post comments using push. I want to display the data I retrieve with the following;

fbl.child         


        
18条回答
  •  有刺的猬
    2020-11-22 12:21

    I have a date variable (long) and wanted to keep the newest items on top of the list. So what I did was:

    • Add a new long field 'dateInverse'
    • Add a new method called 'getDateInverse', which just returns: Long.MAX_VALUE - date;
    • Create my query with: .orderByChild("dateInverse")
    • Presto! :p

提交回复
热议问题