Exception when try to setError() in an editText inside a Popup Window

六月ゝ 毕业季﹏ 提交于 2020-01-15 13:36:09

问题


This is my code:

 if(textNomeGiocatore.getText().toString().equals("")){
                InputMethodManager imm = (InputMethodManager)getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(textNomeGiocatore.getWindowToken(), 0);

                textNomeGiocatore.setError("Nome giocatore necessario");





            }

I have an error in the row :

 textNomeGiocatore.setError("Nome giocatore necessario");

this is the error :

 android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@426940a8 is not valid; is your activity running?

I try to post delayed the error message without resoult.

Someone Can help me?


回答1:


0Please try this:

   if(textNomeGiocatore.getText().toString().equals("")) {
        InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputManager != null &&  getCurrentFocus() != null) {
                inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        }
        textNomeGiocatore.requestFocus() 
        textNomeGiocatore.setError("Nome giocatore necessario");
    }


来源:https://stackoverflow.com/questions/30453580/exception-when-try-to-seterror-in-an-edittext-inside-a-popup-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!