我有一个对话框,它是一个计算器。一旦用户点击该计算器的OK按钮,就必须计算免费发行/折扣,取决于标志需要显示构造改变对话框。设计和设计显示警告对话框是可以的。
我的问题是显示对话框计算器,在那里我单击确定,它显示警报对话框,没有等待警报对话框结果执行代码的结果。我该怎么办,一旦获得Alert对话结果,只需要保留部分。
这是我的代码:
dialog = new Dialog(SalesActivityGroup.group.getParent());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
View vLoad = LayoutInflater.from(SalesActivityGroup.group.getParent()).inflate(R.layout.key_pad, null);
dialog.setContentView(vLoad);
android.view.WindowManager.LayoutParams lp= dialog.getWindow().getAttributes();
lp.x = xVal;
lp.y = yVal;
lp.width = LayoutParams.WRAP_CONTENT;
lp.height = LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP | Gravity.LEFT;
lp.dimAmount = 0;
dialog.getWindow().setAttributes(lp);
dialog.setCancelable(false);
keyamDisplay = (TextView)dialog.findViewById(R.id.keyamDisplay);
TextView txtName = (TextView)dialog.findViewById(R.id.txtName);
txtName.setText("Q");
Button txtDialogOK = (Button)dialog.findViewById(R.id.txtDialogOK);
txtDialogOK.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
popup = false;
try {
String productCode= txtCode.getText().toString();
String number = txtNumber.getText().toString();
int iVal = 0; //getting i value
if(number != "" && !number.equals("")){
iVal = Integer.parseInt(number);
}
String enteredQty = keyAmount.toString();
String tmpEnterdPrice = txtPrice.getText().toString();
double enterdPrice = Double.parseDouble(tmpEnterdPrice);
if(tmpQty > Double.parseDouble(stk.getText().toString())){
if(disStockVali.equals("1")) { //Confirmation message if yes no discount , only entered <<Qty>>
AlertDialog.Builder disco = new AlertDialog.Builder(SalesActivityGroup.group.getParent());
disco.setMessage("Discount Qty Not Enough!! \n Do you want to continue without discount ?");
disco.setCancelable(false);
disco.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
disStatus ="YES";
}
});
disco.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
disStatus ="NO";
}
});
disco.setTitle("Qty Not Enough");
disco.show();
System.out.println("==disStatus=="+disStatus);
if(disStatus.equals("YES")) {
System.out.println("==YES YES====");
System.out.println("=YES=QTY==" + txtQty.getText().toString());
disPro.setDiscountQty(0);
disPro.setDiscountProductCode("");
disPro.setDiscountValue(0.00);
}else {
enteredQty = "0";
txtQty.setText("0");
valueInDouble = 0.00;
disPro.setDiscountQty(0);
disPro.setDiscountProductCode("");
disPro.setDiscountValue(0.00);
}
}
System.out.println("==2 QTY ==" +txtQty.getText().toString());
System.out.println("==valueInDouble ==" +valueInDouble);
double tmpNet = valueInDouble - disPro.getDiscountValue();
txtVal.setText(df.format(tmpNet));
// TAX calculation
VatTax vatTax = calculateLineTax(productCode,Double.parseDouble(txtVal.getText().toString()));
}catch (Exception e) {
e.printStackTrace();
}
dialog.dismiss();
}
});
dialog.show();
请帮帮我。
答案 0 :(得分:0)
你期待这样吗?
public void Alert(String text, String title)
{
AlertDialog dialog=new AlertDialog.Builder(context).create();
dialog.setTitle(title);
dialog.setMessage(text);
if(!title.equals("") && !text.equals(""))
{
dialog.setButton("OK",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
AlertDialog dg=new AlertDialog.Builder(context).create();
dg.setTitle("OK Pressed");
dg.show();
}
});
dialog.setButton2("Cancel",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
AlertDialog dg=new AlertDialog.Builder(context).create();
dg.setTitle("Cancel Pressed");
dg.show();
}
});
}
dialog.show();
}