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
  • 385
  • 5
  • 21

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

ʍѳђઽ૯ท
  • 16,177
  • 7
  • 51
  • 106