So I have been quite successful in all my Firestore use cases but this is messing me up.
So I have this collection that has a bunch of documents, each with an array of strings.
What I am trying to accomplish is to populate my list with a random array (one string per line) when I press a button. Not very successful, and this is as far I got.
Any ideas? Thanks
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()
})
EDIT: DATABSE STRUCTURE