Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将随机数组从firebase加载到列表_Android_Firebase_Kotlin_Google Cloud Firestore - Fatal编程技术网

Android 将随机数组从firebase加载到列表

Android 将随机数组从firebase加载到列表,android,firebase,kotlin,google-cloud-firestore,Android,Firebase,Kotlin,Google Cloud Firestore,因此,我在所有Firestore用例中都非常成功,但这让我很困惑 我有一个集合,它有一堆文档,每个文档都有一个字符串数组 我试图完成的是在按下按钮时用随机数组(每行一个字符串)填充列表。 不是很成功,这就是我所能做到的 有什么想法吗?谢谢 val workoutNewList = workoutListView val workoutNewListAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_

因此,我在所有Firestore用例中都非常成功,但这让我很困惑

我有一个集合,它有一堆文档,每个文档都有一个字符串数组

我试图完成的是在按下按钮时用随机数组(每行一个字符串)填充列表。 不是很成功,这就是我所能做到的

有什么想法吗?谢谢

        val workoutNewList = workoutListView
    val workoutNewListAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, workoutList)
    workoutNewList.adapter = workoutNewListAdapter


    val docRef = db.collection("Benchmark Wods Girls")

    docRef.addSnapshotListener(EventListener<QuerySnapshot> { value, e ->

        if (e != null) {
            Log.w("TAG", "Listen failed.", e)
            return@EventListener
        }

        for (document in value.documents) {
            val data = document.data
            val categories = data["exercises"] as String



            workoutList.add(categories)
        }

        randomWorkoutBtn.setOnClickListener {



        var workoutCount: Int = workoutList.size
        var randomWorkoutNumber: Int = Random().nextInt(workoutCount)


        val randomWorkout = ArrayList<String>()
        for (i in 1..9) {
            randomWorkout.add(workoutList.get(randomWorkoutNumber))
        } }


        workoutNewListAdapter.notifyDataSetChanged()

    })
val workoutNewList=workoutListView
val workoutNewListAdapter=ArrayAdapter(这是android.R.layout.simple\u list\u item\u 1,workoutList)
workoutNewList.adapter=workoutnewlistapter
val docRef=db.collection(“基准Wods女孩”)
docRef.addSnapshotListener(EventListener{value,e->
如果(e!=null){
Log.w(“标记”,“侦听失败”,e)
return@EventListener
}
for(价值中的文档。文档){
val数据=document.data
val categories=数据[“练习”]作为字符串
workoutList.add(类别)
}
randomWorkoutBtn.setOnClickListener{
var workoutCount:Int=workoutList.size
var randomWorkoutNumber:Int=Random().nextInt(workoutCount)
val random=ArrayList()
对于(1..9中的i){
添加(workoutList.get(randomWorkoutNumber))
} }
workoutNewListAdapter.notifyDataSetChanged()
})

编辑:数据库结构


请添加您的数据库结构。对不起,Alex。我将在我的帖子上放一个截图。照顾好EDITDone:)。。你能看到吗?要获取包含你正在寻找的数组的随机文档,请查看我的答案。它是用Java编写的,但是你可以简单地转换成Kotlin。。。但是我不知道在for循环中该做什么:/你能给我看些东西吗?谢谢