gpt4 book ai didi

android - 如何使用Kotlin将runOnUiThread中的append应用到Android

转载 作者:行者123 更新时间:2023-12-02 13:25:30 26 4
gpt4 key购买 nike

我在Android的Kotlin中有这段代码,我需要将append应用于messageReceived变量。我该怎么做?

private lateinit var messageReceived: TextView

this.messageReceived = findViewById(R.id.messageRreceived)

private fun updateReceivedMessage(newPayload: String) {
runOnUiThread { messageReceived.text = newPayload }
}

最佳答案

首先获取文本,然后设置新文本

private fun updateReceivedMessage(newPayload: String) {
runOnUiThread {
val previousText = messageReceived.text.toString()
messageReceived.text = "$previousText $newPayload"
}
}
您可以通过换行使其更具可读性
messageReceived.text = "$previousText\n$newPayload"

关于android - 如何使用Kotlin将runOnUiThread中的append应用到Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64394975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com