1

I want to hide the keyboard:

View view = this.getCurrentFocus();

if (view != null) {
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
});

Now I have the problem, that getCurrentFocus and getSystemService are colored red and it says:

Cannot resolve method getCurrentFocus() / getSystemService()

What am I doing wrong?

Thanks for your help!

Cyb3rKo
  • 340
  • 4
  • 18

1 Answers1

1

This getSystemService should have a context before:

InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); // or context

or getActivity() or similiar codes to get the context.

Check out the codes: Close/hide the Android Soft Keyboard

ʍѳђઽ૯ท
  • 15,369
  • 7
  • 47
  • 103