gpt4 book ai didi

Android Toast 消息未显示

转载 作者:IT王子 更新时间:2023-10-28 23:41:41 27 4
gpt4 key购买 nike

我有按钮。当用户点击按钮时,有一些条件,条件不满足则需要显示 Toast 但不显示 Toast 消息...

代码:已编辑

 Button addMe = (Button)findViewById(R.id.addMe);
addMe.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(selectedReason.equals("--Select--")){
Log.i("TAG","-----");
Toast.makeText(getBaseContext(), "Reason can not be blank", Toast.LENGTH_SHORT).show();
}else if(selectedType.equals("--Select--")){
Toast.makeText(getParent(), "Discount type can not be blank", Toast.LENGTH_SHORT).show();
}else{
if(selectedType.equals("Value")){
if(spc_amount.getText().toString().equals("")){
Log.i("TAG","-----");
Toast.makeText(getBaseContext(), "Discount type can not be blank", Toast.LENGTH_SHORT).show();
}else{
if(Double.parseDouble(spc_amount.getText().toString()) > invoiceValue){
Toast.makeText(getBaseContext(), "Amonut can not be grater than invoice", Toast.LENGTH_SHORT).show();
}else{
Discount dis = new Discount();
dis.setCriteriaName(selectedReason);
dis.setDiscountValue(Double.parseDouble(spc_amount.getText().toString()));
spDisList.put(1,dis);
tl.removeAllViews();
loadTableLayout();
}

}
}
}
}
});

我尝试过使用 getParent()getApplicationContext()SpecialDiscountActivity.thisgetBaseContext() 的上下文> 但不工作....

Toast 消息来自 Tab Activity Group

最佳答案

试试:

Toast.makeText(getBaseContext(), "Reason can not be blank", Toast.LENGTH_SHORT).show();

正是您在各处省略的 .show() 导致所有 toast 实例化,但从不执行。

关于Android Toast 消息未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7803256/

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