【发布时间】:2021-08-14 23:43:48
【问题描述】:
我是 android studio 的新手,我在旋转屏幕时遇到问题,搜索栏进度将重置为 0,我曾尝试使用保存的实例状态但进度仍然重置它,谁能帮助我给我一些解决方案?
我收到此错误 类型不匹配:推断类型是字符串?但需要 Int
谢谢大家。希望你们早日回来
上面是 MainActivity.kt 中的代码
//the bottom one
var no:Int=0
private val SEEKBAR ="seekbar"
//Inside the onCreate
if (savedInstanceState !=null) {
val value = savedInstanceState.getString(SEEKBAR)
seekbar1.progress=value
no= value?.toInt() ?:0
}
//after the onCreate
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val seekbar1 = seekbar1.progress.toString()
outState.putString(SEEKBAR,seekbar1)
}
【问题讨论】:
标签: android arrays android-studio kotlin android-seekbar