我有按钮。当用户单击按钮时,有一些条件,该条件不满足则需要显示 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
原文由 Piraba 发布,翻译遵循 CC BY-SA 4.0 许可协议
我确实喜欢这个