Ejemplo n.º 1
0
  /** @param view */
  public static void showSoftKeyboard(final View view) {
    if (view == null) {
      return;
    }

    final Runnable action =
        new Runnable() {
          @Override
          public void run() {
            final InputMethodManager imm =
                (InputMethodManager)
                    view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
          }
        };

    final View.OnFocusChangeListener restoreOnFocusChangeListener = view.getOnFocusChangeListener();

    final View.OnFocusChangeListener temporaryOnFocusChangeListener =
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(final View v, final boolean hasFocus) {
            view.setOnFocusChangeListener(restoreOnFocusChangeListener);
            view.postDelayed(action, 25);
          }
        };

    view.setOnFocusChangeListener(temporaryOnFocusChangeListener);
    view.requestFocus();
  }
Ejemplo n.º 2
0
  /** @param view */
  public static void hideSoftKeyboard(final View view) {
    if (view == null) {
      return;
    }

    final Runnable action =
        new Runnable() {
          @Override
          public void run() {
            final InputMethodManager imm =
                (InputMethodManager)
                    view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(
                view.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
          }
        };

    view.postDelayed(action, 25);
  }