0

I am listening to an emit from a live data and want to loop through the list to Log them. if I do myList.toString(), I can see all 10 elements of the list. But my loop stops after logging two elements:

    myLiveData.observe(this, Observer {
       val items : List<Items> = it
    
        Log.i("TAG", "${items.toString()}") // shows all 10 items correctly

       //log each item

       for(i: Item in items){
        Log.i("TAG", i.code)
       }

     // above loop shows the first two items only.
       

    })

how can I loop all the items that I got through the observable?

Erick
  • 63
  • 4
  • 1
    I don't see any issues in the code above. But I notice you're using `i.code` instead of `i.toString()`, so you shouldn't necessarily expect the same output. List.toString() would be calling `toString()` on each item. So maybe there's an issue with your `Item.code` property. – Tenfour04 Jul 05 '22 at 15:50
  • Check the log isn't hiding a bunch of the lines - when similar stuff gets logged all at once, it can be suppressed with a *chatty* message. More info on that here: https://stackoverflow.com/q/34587273 - but don't worry, a basic `for` loop is going to iterate over all of `items` – cactustictacs Jul 05 '22 at 18:22

0 Answers0