gpt4 book ai didi

java - 按下按钮时状态不会改变

转载 作者:行者123 更新时间:2023-12-01 18:23:27 26 4
gpt4 key购买 nike

每当我按下按钮时,它应该更改文本,并且还更改 boolean 值,但这不起作用。有什么帮助吗?谢谢

onCreate 之前:

public boolean status = false;

按钮点击:

case R.id.saveButton:   

if (status != true) {
currentStatus.setText("Current status: In need of help!");
status = true;
}
if (status != false) {
currentStatus.setText("Current status: Fine.");
status = false;
}
break;

最佳答案

if(status){
currentStatus.setText("Current status: Fine.");
status = false;
}else {
currentStatus.setText("Current status: In need of help!");
status = true
}

或使用三元运算符:

currentStatus.setText(status ? "Current status: Fine." : "Current status: In need of help!");
status = !status;//toggle boolean value

关于java - 按下按钮时状态不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26991207/

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