Omar
Omar

Reputation: 8145

How to create a Notification cancel dialog?

I have a notification which tells the user that its downloading a file with its progress..
I want to make a dialog with some textviews displaying some info and 2 buttons which are Close and Stop (stops the download).
How can I do this?

Upvotes: 0

Views: 246

Answers (2)

salahy
salahy

Reputation: 1197

you can use the AlertDialog Class

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

Upvotes: 1

Himanshu Virmani
Himanshu Virmani

Reputation: 2460

you can use a custom dialog where your text views are defined in xml and you can use your xml to set as view in your custom dialog box.

you can code like this:-

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

Upvotes: 0

Related Questions