2012-05-11 69 views
0

我有对话框,它是一个calculator.Once用户点击确定按钮从计算器,必须计算自由问题/折扣,取决于标志需要显示构象改变对话框。显示警报对话框的设计&正常。在Android中的对话框中显示警报对话框?

我的问题是显示对话框计算器,在那里我点击确定,它显示警报对话框,没有等待警告对话结果做代码的结果。我怎么做,一旦获得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();  

enter image description here

请帮助我。

回答

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

    } 
+0

对话框内显示的警告对话框中显示well.My要求,需要等到用户结果 – Piraba

+0

做你检查这一点:http://stackoverflow.com/questions/4381296/android-wait-on-user - 输入 - 从 - 对话 – Ponmalar