修复 EditText 类型不匹配问题,使用 setText 替代 text 赋值
This commit is contained in:
@@ -85,7 +85,7 @@ class MainActivity : AppCompatActivity() {
|
||||
loadPromptsFromConfig()
|
||||
|
||||
outputStatusLabel.text = "等待发送"
|
||||
outputTextView.text = "发送消息后结果将在此显示"
|
||||
outputTextView.setText("发送消息后结果将在此显示")
|
||||
|
||||
// Setup prompt selector listener
|
||||
promptSelector.setOnItemSelectedListener(object : android.widget.AdapterView.OnItemSelectedListener {
|
||||
@@ -117,7 +117,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val inputText = inputEditText.text.toString()
|
||||
if (inputText.isNotEmpty()) {
|
||||
outputStatusLabel.text = "连接中…"
|
||||
outputTextView.text = "正在生成..."
|
||||
outputTextView.setText("正在生成...")
|
||||
|
||||
val promptContent = promptContentText.text.toString()
|
||||
val fullContent = if (promptContent.isNotEmpty() && promptContent != "无特殊指令") {
|
||||
@@ -178,20 +178,20 @@ class MainActivity : AppCompatActivity() {
|
||||
val message = choices.getJSONObject(0).getJSONObject("message")
|
||||
val content = message.getString("content")
|
||||
outputStatusLabel.text = "已完成"
|
||||
outputTextView.text = content
|
||||
outputTextView.setText(content)
|
||||
} else {
|
||||
outputStatusLabel.text = "发生错误"
|
||||
outputTextView.text = "API 返回空结果"
|
||||
outputTextView.setText("API 返回空结果")
|
||||
}
|
||||
} else {
|
||||
outputStatusLabel.text = "发生错误"
|
||||
outputTextView.text = "API 错误: ${response.code} ${response.message}"
|
||||
outputTextView.setText("API 错误: ${response.code} ${response.message}")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
outputStatusLabel.text = "发生错误"
|
||||
outputTextView.text = "错误: ${e.message}"
|
||||
outputTextView.setText("错误: ${e.message}")
|
||||
}
|
||||
Log.e("MainActivity", "Error calling API", e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user