如何修复 kotlin 中的字符串大小选择错误?
How to fix string size selection error in kotlin?
val textoData = itemView.findViewById(R.id.texto_data_abastecimento)
textoData.text = abastecimento.datam.toString().subSequence(0..10)
val textoHora = itemView.findViewById<TextView>(R.id.texto_hora_abastecimento)
textoHora.text = abastecimento.hodomDm.toString().subSequence(0..5)
我试图仅使用前 5 个字符在适配器上显示,但最终出现以下错误:
java.lang.StringIndexOutOfBoundsException:长度=0;指数=6
您可以轻松使用Kotlin标准库的substring(0,5)
扩展功能。
textoHora.text = abastecimento.hodomDm.toString().substring(0,5)
val textoData = itemView.findViewById(R.id.texto_data_abastecimento) textoData.text = abastecimento.datam.toString().subSequence(0..10)
val textoHora = itemView.findViewById<TextView>(R.id.texto_hora_abastecimento)
textoHora.text = abastecimento.hodomDm.toString().subSequence(0..5)
我试图仅使用前 5 个字符在适配器上显示,但最终出现以下错误:
java.lang.StringIndexOutOfBoundsException:长度=0;指数=6
您可以轻松使用Kotlin标准库的substring(0,5)
扩展功能。
textoHora.text = abastecimento.hodomDm.toString().substring(0,5)