问题
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