Exception when focusing a EditText in a PopupWindow running on Device

后端 未结 7 2056
别那么骄傲
别那么骄傲 2021-02-12 22:38

I\'m developing a PopUp window for Android, and it\'s working, I added a EditText and a Button on that, when running on ADV this work properly, while running on device, when I f

相关标签:
7条回答
  • 2021-02-12 23:34

    Thank you, TheRedPill! I had the same problem with EditText inside PopupWindow behaving stragely. It worked on Samsung Galaxy S3, HTC One X but crashed on Huawei MediaPad FHD 10. As soon as I started editing the application crashed.

    Your solution:

    editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    

    Solved the issue for me.

    The stack-trace was:

    08-15 15:49:03.690: ERROR/AndroidRuntime(8692): FATAL EXCEPTION: main
        android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@417eefa8 is not valid; is your activity running?
        at android.view.ViewRootImpl.setView(ViewRootImpl.java:585)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
        at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
        at android.view.Window$LocalWindowManager.addView(Window.java:547)
        at android.widget.PopupWindow.invokePopup(PopupWindow.java:988)
        at android.widget.PopupWindow.showAtLocation(PopupWindow.java:845)
        at android.widget.PopupWindow.showAtLocation(PopupWindow.java:809)
        at android.widget.Editor$PinnedPopupWindow.updatePosition(Editor.java:2147)
        at android.widget.Editor$PinnedPopupWindow.show(Editor.java:2104)
        at android.widget.Editor$SuggestionsPopupWindow.show(Editor.java:2349)
        at android.widget.Editor.showSuggestions(Editor.java:1647)
        at android.widget.Editor$1.run(Editor.java:1546)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
    
    0 讨论(0)
提交回复
热议问题