Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is setOnShowListener never called?

Tags:

android

Here is my code:

mDialog.show();
mDialog.setOnShowListener(new OnShowListener() {
  @Override
  public void onShow(DialogInterface dialog) {
    //some code
  }
});

The breakpoints shows that //some code is never called. Can you help me understand what is happening ?

It's API 8 and above (supported by my app)

like image 410
Elad Benda Avatar asked Mar 20 '14 16:03

Elad Benda


2 Answers

I could be wrong but you should set the listener before you call show() on the Dialog.

like image 102
Steve Benett Avatar answered Oct 05 '22 03:10

Steve Benett


Try this:

mDialog.setOnShowListener(new OnShowListener() {
  @Override
  public void onShow(DialogInterface dialog) {
    //some code

  }
});

mDialog.show();

This way you ensure that the listener is registered before the dialog is shown.

like image 34
Tiago Pasqualini Avatar answered Oct 05 '22 05:10

Tiago Pasqualini