0

So, I have created data with a list of documents on Firestore, and I want to retrieve a single document randomly, whenever the Android activity is invoked.

Like for example, I have the following set of documents in the collection "people"

Alex

Abhishek

Nandini

Nancy

and in my Android activity, I have a TextView which will show each of the collection name randomly, whenever I invoke that activity, like when I open the activity, it will show "Nancy" on the textview and again when I reopen, it would show "Abhishek!"

Hope you understood my question, and it will be helpful and anyone can help me in that

Using JAVA code for coding my Android application!

0

2 Answers 2

0

I don't think firebase can get a random doc. You should use a field in your documents to handle that.

For example: if your application is simple, using an incremental number in each document should be enough as you could simply query a random number between 0 and the number of documents-1

Sign up to request clarification or add additional context in comments.

1 Comment

like see all the documents are retrieved using collectionreference, and using for each, we get every document, I want to retrieve one single document in random on android studio!
0

Retrive all the documents and store them in an arraylist and when user clicks the textview, pick a random document from the list. ArrayList.random() this returns a random element from the list.

1 Comment

I tried using random() in the arraylist but it shows, method random is not resolved like I created an arraylist questionlist and I wrote the code as follows - 'questionlist.random()' which is not working!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.