Java转Kotlin

蔡鸿骞
2023-12-01

for循环

for (i in 0 until locationData.size) {
    val city = locationData.getJsonMap(i)
    val value = city.getString("Value")
    options1Items.add(value)
}

until 代表结束数量-1

for (i in cityData.indices) {
    list.add(cityData.getJsonMap(i).getString("Value"))
}

indices代表从0到结束-1

创建可以使用add的list正常kotlin是不可以使用add进行添加的

val list: MutableList<String?> = mutableListOf()

kotlin中editText赋值

binding.spResultDe.text =
    Editable.Factory.getInstance().newEditable("EditText赋值")
 类似资料: