2

Android studio version :2.3.3 The code below is not working and it should hide the keyboard but its not.Please help.

 InputMethodManager imm = (InputMethodManager) 
    getSystemService(Context.INPUT_METHOD_SERVICE);
    public void setImm(InputMethodManager imm) {
    this.imm = imm;
    }
    public InputMethodManager getImm() {
    imm.hideSoftInputFromWindow(urledit.getWindowToken(),0);
    return imm;
    }
rahuman aslam
  • 21
  • 1
  • 1
  • 2
  • Hi, welcome to stack overflow. Please refer the [ask] link for more details on how to ask a question and update your question accordingly. – Jeroen Heier Aug 25 '17 at 04:05

3 Answers3

0
/**
 * Hides the soft keyboard
 */
 public void hideSoftKeyboard() {
   if(getCurrentFocus()!=null) {
   InputMethodManager inputMethodManager = (InputMethodManager) 
 getSystemService(INPUT_METHOD_SERVICE);
   inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
  }
}

 /**
 * Shows the soft keyboard
 */
public void showSoftKeyboard(View view) {
   InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
   view.requestFocus();
   inputMethodManager.showSoftInput(view, 0);
}

Try this to hide and show keyboard

Ankit Kumar
  • 3,663
  • 2
  • 26
  • 38
0

Hope to Useful

public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view == null) {
    view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
Harshit Trivedi
  • 764
  • 9
  • 33
0

Hi use this code and it's working 100%

            View.OnTouchListener disable = new View.OnTouchListener() {
            public boolean onTouch (View v, MotionEvent event) {
            v.onTouchEvent(event);
            InputMethodManager img = 
           (InputMethodManager)v.getContext().getSystemService(INPUT_METHOD_SERVICE);
            if (img != null) {
            img.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
            System.out.println(ee.getSelectionEnd());
            return true;
           }
           };
           //create a Button to setOnTouchListener(event)
           Button ee=new Button(this);
           ee.setOnTouchListener(disable);
yashpal singh
  • 86
  • 2
  • 5