2

I'm new in Android Kotlin and I want to GET an array of help in Firestore into my entity and this is my code:

val appCollection = App.context.db.collection("app")
    val docApp = appCollection.document("info")
    docApp.get().addOnCompleteListener { task ->
        if (task.isSuccessful) {
            val document = task.result
            if (document.exists()) {
                val list = document["help"] as List<*>?
            }
        }
    }

how can i put that list into my entity, and this is my Entity

class Info() : Parcelable{

var help: List<Help>? = null
var howto: List<HowTo>? = null
var info: List<Info>? = null

enter image description here

1 Answer 1

1

As I see in your screenshot, your help array contains objects of type String and not objects of type Help. To read such an array, please change the following field declaration from:

var help: List<Help>? = null

To:

var help: List<String>? = null

If you however need to store Help in the array, then you need to first add such objects accordingly. So your structure might look like this:

Firestore-root
  |
  --- app (collection)
       |
        --- info (document)
             |
             --- help (array)
                  |
                  --- 0
                      |
                      --- fieldOne: valueOne
                      |
                      --- fieldTwo: valueOTwo

To map such an array to a List of custom objects, please check the following article:

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

1 Comment

You're very welcome, Andika.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.