Um, unless I'm missing something...

You can't use the same button because presumably the button to launch
the long-running operation is not in the dialog, it's in the activity
- and dialogs prevent interaction with activity UI elements while
displayed.

What you can do is one of:

1) Build your own dialog with a cancel button;

2) Use Dialog.setOnCancelListener which gets called if the user
presses the Back key; here the dialog is dismissed automatically;

3) Set a key listener in the dialog and check for when the back key is
pressed, something like:

                        mProgressDialog = new ProgressDialog(mActivity);

                        
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        mProgressDialog.setMax(item.fetch_decoded_size / 1024);
                        
mProgressDialog.setTitle(R.string.attachment_dialog_title);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.setOnKeyListener(new OnKeyListener() {
                                @Override
                                public boolean onKey(DialogInterface dialog, 
int keyCode, KeyEvent event) {
                                        if (keyCode == KeyEvent.KEYCODE_BACK && 
event.getAction() ==
KeyEvent.ACTION_UP
                                                        && 
event.getRepeatCount() == 0) {
                                                cancelDownload();
                                                return true;
                                        }
                                        return false;
                                }
                        });

In this code, canceling the operation can take some time, so I made
the dialog non-cancelable to be able display "Canceling...".

-- Kostya

20 декабря 2011 г. 15:32 пользователь B.Arunkumar
<[email protected]> написал:
> Hi,
>
>   This can be done. What I want is a way to use the same button for
> showing the progressdialog and later cancelling it. Probably I should
> go in for some animated imagview instead of progressdialog for my
> requirement, I guess.
>
> Thank you,
> B.Arunkumar
>
> On Dec 20, 3:58 pm, srihari babu <[email protected]> wrote:
>> build custom progress dialog, which is a combination of progress bar  and a
>> button.
>>
>> Regards,
>> Srihari
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to