-3

In continuation of the answer given in Android setError("error") not working in Textview After applying the solution i.e. changing textview to focusable, A keyboard gets pop-up when that textview is clicked. How to hide that.

P.S. I tried onFocusChangeListener and onTouchListener

I want to know where to call this hide keyboard method as I tried this but it's not solving the issue;

    mEndTimeView.setOnClickListener(v -> {
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if(ViewUtils.isKeyboardShown(mEndTimeView.getRootView())){
            imm.hideSoftInputFromWindow(mEndTimeView.getWindowToken(), 0);
        }
        showEndTimePicker();
    });
  • https://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard Try this answer – arjunkn May 23 '18 at 09:05
  • 2
    Possible duplicate of [Close/hide the Android Soft Keyboard](https://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – 2Dee May 23 '18 at 09:07
  • Hi @2Dee, Here I am talking about **TextView** not **EditText**. – Manish Goyal May 23 '18 at 09:14

2 Answers2

1
public static void hideKeyboard(Activity activity) {
View view = activity.findViewById(android.R.id.content);
if (view != null) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}  

Call this method in button click.

Bhupat Bheda
  • 1,988
  • 1
  • 6
  • 13
0

You need this method to hide Soft keyboard.

public void closeKeyboard() {
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

Call this method to hide/close soft keyboard.

halfer
  • 18,701
  • 13
  • 79
  • 158
Sanwal Singh
  • 1,689
  • 3
  • 18
  • 34