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