2012-03-15 30 views
0

當用戶點擊文本編輯器時,對話框計算器將顯示,該時間父活動/屏幕應該被禁用。Android - 當對話框啓用時如何禁用父活動

這是我的代碼:

txtQty.setOnFocusChangeListener(new OnFocusChangeListener() { 
    public void onFocusChange(View v, boolean hasFocus) { 
     if(hasFocus){ 
         keyAmount = new StringBuffer(); 
         if(keyAmount.length() > 0){ 
          keyAmount.delete(0, keyAmount.length()); 
         } 

         int[] origin = new int[2]; 
         v.getLocationOnScreen(origin); 
         final int xVal = origin[0]; 
         final int yVal = origin[1] ; 

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

         dialog.setCancelable(true); 
         dialog.setCanceledOnTouchOutside(true); 
         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(true); 
         keyamDisplay = (TextView)dialog.findViewById(R.id.keyamDisplay); 

         Button txtone = (Button)dialog.findViewById(R.id.txtone); 
         txtone.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("1"); 
           keyamDisplay.setText("" + keyAmount.toString()); 

          } 
         }); 

         Button txttwo = (Button)dialog.findViewById(R.id.txttwo); 
         txttwo.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("2"); 
           keyamDisplay.setText("" + keyAmount.toString()); 

          } 
         }); 

         Button txtthree = (Button)dialog.findViewById(R.id.txtthree); 
         txtthree.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("3"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txtfour = (Button)dialog.findViewById(R.id.txtfour); 
         txtfour.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("4"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txtfive = (Button)dialog.findViewById(R.id.txtfive); 
         txtfive.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("5"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txtsix = (Button)dialog.findViewById(R.id.txtsix); 
         txtsix.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("6"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txtseven = (Button)dialog.findViewById(R.id.txtseven); 
         txtseven.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("7"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txteight = (Button)dialog.findViewById(R.id.txteight); 
         txteight.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("8"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txtnine = (Button)dialog.findViewById(R.id.txtnine); 
         txtnine.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("9"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txtZero = (Button)dialog.findViewById(R.id.txtZero); 
         txtZero.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           keyAmount.append("0"); 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         Button txtdot = (Button)dialog.findViewById(R.id.txtdot); 
         txtdot.setOnClickListener(new OnClickListener() { 
           public void onClick(View v) { 
            keyAmount.append("."); 
            keyamDisplay.setText("" + keyAmount.toString()); 
           } 
         }); 

         Button diaDelete = (Button)dialog.findViewById(R.id.diaDelete); 
         diaDelete.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
          if(keyAmount.length() > 0){ 
           keyAmount.delete(keyAmount.length()-1, keyAmount.length()); 
          } 
           keyamDisplay.setText("" + keyAmount.toString()); 
          } 
         }); 

         ImageButton imageSmileExit = (ImageButton)dialog.findViewById(R.id.imageSmileExit); 
         imageSmileExit.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           dialog.dismiss(); 
          } 
         }); 

         Button txtDialogOK = (Button)dialog.findViewById(R.id.txtDialogOK); 
         txtDialogOK.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
           dialog.dismiss(); 

這是我的屏幕截圖:

enter image description here

+0

你是什麼意思,當你說「父活動/屏幕應該禁用」。 – Varun 2012-03-15 06:44:42

回答

3

我想在你的代碼,而不是dialog.setCancelable(真);使用dialog.setCancelable(false); 並在ok或取消按鈕onclicklistener你必須解僱或取消對話框。

0

嘗試在您的自定義佈局中使用AlertDialog,它完全按照您的要求進行操作。我將它用於EULA。

再見

相關問題