Firebase: Pull random data from Firebase to RecyclerView (android)

后端 未结 1 1846
逝去的感伤
逝去的感伤 2020-12-11 13:11

I made a query to pull only 6 itens from database inside a RecyclerView, but at this time I can only orderByChild, limitToFirst or last. Everything is working fine but...

相关标签:
1条回答
  • 2020-12-11 13:46

    I suggest you also add another variable to your Model class. Something like an "id". And you store random Long values in it. (From 0 to 15 for example). And then create a method that will generate a random value (lets say the method's name is generateRandom()). This way, when you want to get the random data, you can use your query like this:

    query = mDatabase.orderByChild("id").startAt(generateRandom()).limitToFirst(6); 
    
    0 讨论(0)
提交回复
热议问题