2011-10-01 58 views
0

我有一个通知告诉用户,它下载的文件的进度..
我想做一些文本对话框显示一些信息和2个关闭和停止按钮(停止下载)。
我该怎么做?如何创建通知取消对话框?

回答

0

您可以使用自定义对话框,其中您的文本视图在xml中定义,您可以使用您的xml设置为您的自定义对话框中的视图。

,你可以像这样的代码: -

@Override 
protected Dialog onCreateDialog(int id) { 
    LayoutInflater factory = null; 
     factory = LayoutInflater.from(this); 
     dialogView = factory.inflate(R.layout.yourXml, null); 

     return new AlertDialog.Builder(yourActivity.this) 
      .setTitle(R.string.rate_title) 
      .setView(dialogView) 
      .setPositiveButton("Stop", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 

       // Add your stop code here 
       } 
      }) 
      .setNegativeButton("Close", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 

       // dismiss dialog here 

       } 
      }) 
      .create(); 
+0

如何通知与此类连接?每次通知更新时,我可以更新对话框中的内容吗? – Omar

1

可以使用AlertDialog类

AlertDialog.Builder alertbox = new AlertDialog.Builder(this); 
    alertbox.setMessage("Downloading"); 

    alertbox.setPositiveButton("Cancel", new DialogInterface.OnClickListener() { 

     // do something when the button is clicked 
     public void onClick(DialogInterface arg0, int arg1) { 
      ..... //cancel code 
     } 
    }); 

    alertbox.setNegativeButton("Pause", new DialogInterface.OnClickListener() { 

     // do something when the button is clicked 
     public void onClick(DialogInterface arg0, int arg1) { 
      .... //pause code 
     } 
    }); 

    // display box 
    alertbox.show(); 
+0

同一问题:如何将通知与此课程连接?每次通知更新时,我可以更新对话框中的内容吗? – Omar