Null pointer error with hideSoftInputFromWindow

后端 未结 14 716
逝去的感伤
逝去的感伤 2020-12-25 11:32

I get a null pointer exception at this row:

public void hideKeyboard(){ 
InputMethodManager inputManager = (InputMethodManager)            
            this.         


        
14条回答
  •  遥遥无期
    2020-12-25 12:05

    Just use this one:

    public void hideKeyboard(View v){ 
      InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
    

提交回复
热议问题