Amit
Amit

Reputation: 11

How to dismiss the dialog only not the activity which calling that dialog on press of back key?

I am populating a dialog which is having a tab view from an activity. Tab view start different activity on clicking different tab with the help of different intent. If i press back key, activity which is calling dialog is also getting dismissed with dialog. But on press of back key i just wnat to dismiss the dialog not the calling activity. how to do that?

Upvotes: 1

Views: 542

Answers (4)

dbaugh
dbaugh

Reputation: 746

ProgressDialog dialog = ProgressDialog.show(context, "Venues", "Loading...", true, true,     new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    } );

Upvotes: 1

user590849
user590849

Reputation: 11765

there is a default method present in android 2.1 and above called onBackButtonPressed(). it is a part of the activity class.... so in that method just do the following:

dialog.dismiss();

this will not do anything else.. but just close the dialog.

Upvotes: 1

Egor
Egor

Reputation: 40203

Just use the dialog.dismiss() method.

Upvotes: 1

Pim Reijersen
Pim Reijersen

Reputation: 1133

Override the setOnCancelListener of the dialog or the activity onBackPressed depending on your application. Post your code for more accurate awnsers.

Upvotes: 1

Related Questions