小编Dae*_*ark的帖子

如何在 kotlin 中将 List<String> 保存到 SharedPreferences?

在我的项目中,我有一个字符串列表。我想将此列表保存到共享首选项。任何人都可以帮忙吗?

data class select(
    @SerializedName("items")
    var items: MutableList<String>?=null
)
Run Code Online (Sandbox Code Playgroud)

sharedpreferences kotlin android-studio

3
推荐指数
1
解决办法
1719
查看次数

如何在 kotlin 中使用 parseInt?

我使乐趣增加,项目数量减少。我想让 count.text 加上“T”字符。当我尝试编写这样的代码时。错误代码:java.lang.NumberFormatException:对于输入字符串:“1T”我该如何解决这个问题?有人可以帮忙吗??

   fun increaseInteger() {

        var count = findViewById<TextView>(R.id.integer_number)
        count.text=intent.getStringExtra("case")+"T"
        var countResult = parseInt(intent.getStringExtra("case")+"T")
        var countValue = countResult+1
        if (countValue >= 1 && !decrease.isEnabled) { decrease.isEnabled = true}
        intent.putExtra("result",countValue)
        display(countValue)
    }

    fun decreaseInteger() {

        var count = findViewById<TextView>(R.id.integer_number)
        count.text=intent.getStringExtra("case")+"T"
        var countResult = parseInt(intent.getStringExtra("case")+"T")
        var countValue = countResult-1
        if (countValue <= 1) {decrease.isEnabled = false }
        intent.putExtra("result",countValue)
           display(countValue)
    }


Run Code Online (Sandbox Code Playgroud)

parseint kotlin android-studio

3
推荐指数
1
解决办法
1401
查看次数