ShrimpCrackers
ShrimpCrackers

Reputation: 4532

Android dialog dismiss() doesn't close

The custom dialog does dismiss at certain points in my program, for example when they press an "Edit" button, but the dialog will not dismiss if I select something from a list view and press an "Add" button. Both buttons end up using this same code below, but the if statements decide which will execute. Either way, the problem is that pcDialog.dismiss() is outside of the if statements, so it should dismiss always...but it doesn't.

Any ideas on what the problem might be? My dialog is declared outside of any methods as a member.

createDoneBtn.setOnClickListener(
                new View.OnClickListener() 
                {   
                    @Override
                    public void onClick(View v) 
                    {
                        if ( !editingPC )
                        {
                            ...
                        }
                        else if ( editingPC )
                        {
                            ...
                        }
                        adapter.notifyDataSetChanged();
                        pcDialog.dismiss();
                    }
                });

Upvotes: 0

Views: 1666

Answers (2)

Dante
Dante

Reputation: 1094

Why not first debug?

And I think it's best practice to put it in try - catch - finally. Then you can call dismiss in the finally.

Upvotes: 1

Alexander
Alexander

Reputation: 48232

Maybe this one dismisses ok, but your code makes a second one to immediately appear? Or maybe an exception is thrown but gets silently caught so you never step into dismiss() ?

Upvotes: 4

Related Questions