Skip to content Skip to sidebar Skip to footer

Firebase: Pull Random Data From Firebase To RecyclerView (android)

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... I'd like

Solution 1:

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); 

Post a Comment for "Firebase: Pull Random Data From Firebase To RecyclerView (android)"