Android-Show Custom Dialog

后端 未结 6 1719
忘了有多久
忘了有多久 2021-01-24 20:15

In my android application, I am using a custom dialog. When I try to show the dialog, it causes an error. I don\'t know what I am doing wrong, and I am really confused.

<
6条回答
  •  不知归路
    2021-01-24 20:39

    First of all, you're using that method wrong. The point of the createDialog method is to, well, create the dialog and then return it. You're showing the dialog within the method, then not returning it at all, which defeats the purpose of overriding that method at all. You really should just have your own method that creates and displays your dialog.

    Second of all, as AVD posted in the comments to your question, that method of displaying dialogs is deprecated for apps targeting an API for Honeycomb (11) or later.

    Your problem, however, is that you're using the Application Context (getApplicationContext()) object to display a dialog that should belong to your Activity. You should pass in this instead to use the Activity context and that will fix your error.

提交回复
热议问题