我有一个按钮,当用户点击该按钮时,如果满足某些条件,则需要显示 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.this
和getBaseContext()
来操作上下文,但都没有起作用...
这个Toast
消息出现在Tab Activity Group
下面。
runOnUiThread
。例如:runOnUiThread(() -> Toast.makeText(getApplicationContext(), " ...", Toast.LENGTH_LONG).show());
- Atan