gpt4 book ai didi

android - 单击按钮时我的 toast 不起作用,它强制关闭并重新启动主要 Activity

转载 作者:行者123 更新时间:2023-11-30 01:55:38 25 4
gpt4 key购买 nike

    Button btn = (Button) findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
Double s1 = 0.0;
s1 = Double.parseDouble(height.getText().toString());
Double s2 = 0.0;
s2 = Double.parseDouble(weight.getText().toString());
if (height.getText().length() == 0 || weight.getText().length() == 0 || (height.getText().length() == 0 && weight.getText().length() == 0)) {
Context context = getApplicationContext();
CharSequence text = "Enter the missing values";
int duration = Toast.LENGTH_LONG;
final Toast tost = Toast.makeText(context, text, duration);

tost.show();
} else {
Double bmi;
bmi = s2 / (s1 * s1);
it.putExtra("bmi_val", bmi);
startActivity(it);
}


}
});

最佳答案

Toast不能用Application Context,必须用Activity

关于android - 单击按钮时我的 toast 不起作用,它强制关闭并重新启动主要 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32282909/

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