Linked Questions

Popular Questions

I'm loading JSON data from internet, capturing data about items, like name, author and imageurl. Then I want to load them one under the other so I put them into the listview. I only add them once as a custom class, that only holds those variables.

I'm having a problem with those values duplicating and not appearing as they should. For example, it would load first 5 items(out of 20) and it would repeat them over the remaining 15. I don't understand why that's happening, also tried with looping over listview's items array and printing them out and they are all different, also tried doing refresh() on them, but it doesn't seem to change anything at all.

I'm adding a code that I use to create the listview and the piece that I'm using to fill it in.

val lv = listview<Item>{
    anchorpaneConstraints {
        topAnchor = 0.0
        bottomAnchor = 0.0
        leftAnchor = 0.0
        rightAnchor = 0.0
    }
    cellFormat {
        graphic = cache {
            form {
                fieldset {
                    hbox {
                        spacing = 10.0
                        println(it.name)
                        println(it.author)
                        println(it.imgurl)
                        println(it.desc)
                        imageview {
                            image = Image(it.imgurl)
                            prefWidth(256.0)
                            prefHeight(256.0)

                        }
                        vbox {
                            field("Name") {
                                label(it.name)
                            }
                            field("Author") {
                                label(it.author)
                            }
                            field("Description") {
                                label {
                                    text = it.desc
                                    wrapWidth = 150
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

val tmpItems = items.clone() as ArrayList<JsonObject>()
val arr = ArrayList<Item>()
for (m in tmpItems) {
    arr.add(
    Item(
        m["name"].toString(),
    m["author"].toString(),
    m["desc"].toString(),
    m["imgUrl"].toString()
    )
)
}
lv.items.addAll(arr)

I expected the output to be 20 unique items, as that's what's in the lv.items, but the shown result is 5 unique items repeated over 20 lines.

Related Questions