1

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?

Luke
  • 517
  • 10
  • 29
  • Try this link:- http://stackoverflow.com/questions/8782250/popupwindow-badtokenexception-unable-to-add-window-token-null-is-not-valid – NehaK May 26 '15 at 08:44
  • Please, try this: http://stackoverflow.com/a/14488827/1796309 – Aleksandr May 26 '15 at 08:44

1 Answers1

0

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");
    }
Kantesh
  • 333
  • 4
  • 13
  • Try calling edittext.requestFocus() before calling set error. – Kantesh May 26 '15 at 09:26
  • Don't solve the problem.. the problem is that can't put a popup over another popup, or something similar – Luke May 26 '15 at 09:42
  • Then instead of parent popup use Dialog or Dialog fragment. – Kantesh May 26 '15 at 09:45
  • I have to use Dialog instead of PopupWindow? – Luke May 26 '15 at 09:49
  • I have the same problem, but instead you use dialog, there are another way to get the same result as set error. You can make your own layout to show above/below the edittext. The layout can be just simpl textview with red color or more complex layout depends on your need – HendraWD Dec 15 '15 at 04:50