JavaEnthusias
JavaEnthusias

Reputation: 31

Keyboard and Focus issue in PopupWindow

I am showing a popup window , if i initialize it as follows :

popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(false);

And

    @Override
    public void onBackPressed() {

       if (popupWindow.isShowing()) {
          showConfirmationDialogForExit();
       } else {
           super.onBackPressed();
       }

    }

The Keyboard in my PopupWindow doesn't open ( the popupWindow has EditText ). Also i have kept a dialog box to confirm the exit of the screen on Back Press which works.

Now opposite to this , if i keep

popupWindow.setFocusable(true);

The keyboard opens and works but the onBackPressed() doesn't check the

popupWindow.isShowing()

here my question is , i want to achieve the backpress check when the popup window is showing and also the keyboard needs to be worked when click on the EditText on that popupWindow.

The solutions i have gone through suggests me to keep

popupWindow.setFocusable(true);

but i am not be able to achieve the goals i am looking for.

Please guide me.

Upvotes: 0

Views: 2074

Answers (1)

TomD
TomD

Reputation: 614

try

popWindow.setFocusable(true);
popWindow.update();

This updates the state of the popup window, if it is currently being displayed, from the currently set state.

If that don't work for you for some reason, you can always just set a local flag when you open the popWindow....

boolean popupshowing = true;

And then use that to check if it is open or not. (I agree it isn't the most elegant solution)

Upvotes: 1

Related Questions