Dialog problem: requestFeature() must be called before adding content

前端 未结 9 507
名媛妹妹
名媛妹妹 2020-12-31 02:39

I\'m creating a custom dialog containing an EditText so that I can get text data from the user:

final EditText newKey = (EditText) findViewById(R.id.dialog_r         


        
相关标签:
9条回答
  • 2020-12-31 03:37

    Also make sure you are not returning an already-shown dialog. For example, ProgressDialog has a handy static method show() which takes some parameters and returns a ProgressDialog. Turns out you can't use that method and return the resulting ProgressDialog, because then when the OS tries to show it (and it's already shown), it will throw this same exception.

    Beware, too: the above behavior is experienced on the Android emulator, but it actually did not throw an exception and worked just fine on my Droid Incredible running 2.2.

    0 讨论(0)
  • 2020-12-31 03:39

    The exact way to solve this problem:

    requestFeature(int) is a method of Window. You have to import this class (android.view.Window).

    And you have to get the Window of the AlertDialog.Builder object. Then call requestFeature(int). The input parameter is a constant of Window.

    keyBuilder.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    0 讨论(0)
  • 2020-12-31 03:41

    I had a similar problem. But my dialog was to be displayed for IME. When I switched to Dialog instead of AlertDialog, and omitted create, the program worked for me.

    0 讨论(0)
提交回复
热议问题