0

In my scenario I have an EditText that gains the focus. When I close the keyboard using the back button, I would like to catch that event and do some stuff like give the focus to another view.

How do I get the keyboard onclose event?

2 Answers 2

1

there is cabback for softkeyboard. I have used this code snippet, hnestly i have forgot from where :(

final View activityRootView = findViewById(R.id.loging_rootview);
        activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
                new OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        int heightDiff = activityRootView.getRootView()
                                .getHeight()
                            - activityRootView.getHeight();
                        if (heightDiff > 138) { // if more than 100 pixels, its
                            // probably a keyboard...

                            logo.setVisibility(View.GONE);
                        } else {

                            logo.setVisibility(View.VISIBLE);
                        }
                    }
                });
1

You can get return button as

editText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// You can identify which key pressed buy checking keyCode value
// with KeyEvent.KEYCODE

   if (keyCode == KeyEvent.KEYCODE_ENTER && KeyEvent.ACTION_DOWN == vent.getAction())     {
          // YOUR CODE HERE
   }

   return false;
   }
});

EDIT :

There is no events occurs when soft keyboard hides. see this Question will help you to solve your problem

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.