0

我有一个对话框,它是一个计算器。一旦用户从该计算器单击 OK 按钮,必须计算免费发行/折扣,这取决于需要显示构象更改对话框的标志。设计和显示警报对话框是可以的。

我的问题是显示对话框计算器,在那里我单击 OK ,它显示了警报对话框,无需等待警报对话框结果执行代码的结果。我该怎么办,一旦它得到警报对话框结果只需要做保留部分。

这是我的代码:

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();    

在此处输入图像描述

请帮帮我。

4

1 回答 1

0

Are you expecting like this?

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();

    }
于 2012-05-11T09:03:44.143 回答