-1

我有以下代码:

  val  itemSize = buttonTexts.size
    var  position = 0

    for  (i in  0  until itemSize) {
        if (i % 3 == 0) {
            Row(
                horizontalArrangement = Arrangement.SpaceEvenly,
                modifier = Modifier.fillMaxWidth()
            ) {
                for (j in 0 until 3) {
                    if (position.inc() <= itemSize) {

                            MusuButton(buttonText = buttonTexts[i]) { checkCorrect(it) }

                    }

                }
            
                }
        }
    }

问题是我在按钮中得到相同的文本 3 次,这是有道理的,因为循环。我想要做的是有多行 3 个按钮,但按钮文本中有许多项目,并将每个文本用于按钮文本

4

1 回答 1

-1

我通过更改以下内容使其工作。

MusuButton(buttonText = buttonTexts[position++) { checkCorrect(it) }

于 2021-10-19T10:59:59.747 回答