Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I made 10 different arrays in Firestore.

private var list:MutableList<Int>?=null
private var images:MutableList<MutableList<String>?>?=null
private var imagesList:MutableList<String>?=null
private val db = Firebase.firestore
private val groupOne =db.document("animal_voices/level_one").get()
private val groupTwo =db.document("animal_voices/level_two").get()
private val groupThree =db.document("animal_voices/level_three").get()
private val groupFour =db.document("animal_voices/level_four").get()
private val groupFive =db.document("animal_voices/level_five").get()
private val groupSix =db.document("animal_voices/level_six").get()
private val groupSeven =db.document("animal_voices/level_seven").get()
private val groupEight =db.document("animal_voices/level_eight").get()
private val groupNine =db.document("animal_voices/level_nine").get()
private val groupTen =db.document("animal_voices/level_ten").get()

Then called them in interface.

fun getFirestoreList(task: Task<DocumentSnapshot>,string: String): MutableList<String>? {
    var liste:MutableList<String>?=null
    task.addOnSuccessListener {
        if(it!=null){
            println("HEY")
            liste = it.get(string) as MutableList<String>
            println(liste)
        }else{
            println("NOOO")
        }
    }
    println("liste= $liste")
    return liste
}

In ViewPagerAdapter's onBindViewHolder method i' m calling this function:

private fun listOfLists(){
    images?.add(0, getFirestoreList(groupOne,"first"))
    Log.d(TAG, "imagesList:$imagesList")
    Log.d(TAG, "images:$images")
    Log.d(TAG, "imagesList:$images")
    Toast.makeText(context,"Here i am!!!",Toast.LENGTH_SHORT).show()
    val x =getFirestoreList(groupTwo,"second")
    print("x= $x")
    images?.add(1,getFirestoreList(groupTwo,"second"))
    images?.add(2,getFirestoreList(groupThree,"third"))
    images?.add(3,getFirestoreList(groupFour,"fourth"))
    images?.add(4,getFirestoreList(groupFive,"fifth"))
    images?.add(5,getFirestoreList(groupSix,"sixth"))
    images?.add(6,getFirestoreList(groupSeven,"seventh"))
    images?.add(7,getFirestoreList(groupEight,"eighth"))
    images?.add(8,getFirestoreList(groupNine,"ninth"))
    images?.add(9,getFirestoreList(groupTen,"tenth"))
    images?.shuffle()
    Log.d(TAG, "images:$images")
}

With this method i am trying to getting list from interface for each document. My problem is i can not get list from getFirestoreList. It returns null. In addOnSuccessListener it is printing the list that i want but it won't from outside of it. I have tried to write this function in ViewPagerAdapter class but no luck so far. Can you tell me where is my problem?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
380 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...