我认为您之前可以创建一个通用字符串变量,当单击某个按钮时会更改该变量,然后您可以在将出现的 toast 中显示此变量。例如:
var selectedString:String = ""
然后分配另一个值:
selectedString = "some_data"
然后在吐司中展示:
Toast.makeText(this, selectedString , Toast.LENGTH_SHORT).show()
更新
通常在单击按钮后,您将分配最新的字符串,该字符串将在 toast 中表示。所以之后,你只需要分析存储的变量:
when(selectedString){
"test_1" -> moveFun(1)
"test_2" -> moveFun(1)
}
然后我们必须创建移动到下一个屏幕的函数:
fun moveFun(toWhich:Int)
{
var intent:Intent?=null
when(toWhich){
1-> intent = Intent(this, FirstActivity::java.class)
2-> intent = Intent(this, SecondActivity::java.class)
}
if(intent!=null){
startActivity(intent)
}
}
更新 2.0
给selectedString赋值的例子:
selectedString = if(success_condition){
"good"
}else{
"bad"
}
然后在 Toast 中显示:
Toast.makeText(this, selectedString , Toast.LENGTH_SHORT).show()
然后分析它:)