2010-10-28 71 views
1

我將動態消息成功添加到我的progressdialog.But時添加按鈕它不會按下按鈕請幫助我。如何動態添加按鈕進度對話框android?

private Handler progressHandler = new Handler() { 

      @Override 
      public void handleMessage(Message msg) { 

       // process incoming messages here 
       switch (msg.what) { 

       case 0: 
        // update progress bar 
        progressDialog.setMessage("" + (String) msg.obj); 
        break; 
       case 1: 
        progressDialog.setMessage("" + (String) msg.obj); 
        finish(); 
        break; 
       case 2: 
        Log.d(TAG,"in case 2........."); 
//     progressDialog.cancel(); 
        progressDialog.setMessage("" + (String) msg.obj); 
        progressDialog.setButton("HOME", new DialogInterface.OnClickListener() { 

         @Override 
         public void onClick(DialogInterface dialog, int which) { 
//       progressDialog.cancel(); 
          finish(); 

         } 
        }); 
        break; 

       } 
       super.handleMessage(msg); 
      } 

     }; 

問候, Rajendar是

+0

嘿ADIT,我有類似的需求。你能得到你想要的東西嗎?請分享您的代碼.. – Nepster 2014-06-17 12:45:59

回答

-2

我只是改變了代碼,以這種方式爲我的便於學習。

private Handler progressHandler = new Handler() { 

      @Override 
      public void handleMessage(Message msg) { 

       // process incoming messages here 
       switch (msg.what) { 

       case 0: 
        // update progress bar 
        progressDialog = new ProgressDialog(context); 

        progressDialog.setMessage("" + (String) msg.obj); 
        progressDialog.show(); 
        break; 

       case 1: 
        Log.d(TAG,"in case 1........."); 
        progressDialog.dismiss(); 


        AlertDialog.Builder builder = new AlertDialog.Builder(context); 
         AlertDialog alertDialog = builder.create(); 
         alertDialog.setTitle("Dialog"); 
         alertDialog.setMessage("" + (String) msg.obj); 
         alertDialog.setButton("HOME", new DialogInterface.OnClickListener() { 

         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          finish(); 

         } 
        }); 
        alertDialog.show(); 


        break; 

       } 
       super.handleMessage(msg); 
      } 

     }; 

如果任何人知道如何添加動態按鈕進度對話框,請回復。

Regards, Rajendar Are。