0

I Want to close popupWindow after pressing backbutton. The popUp Window is in View Pager which is in Activity. The back button doesnt react for any touch.(when the popUp is close works fine) I set the BackgroundDrawable and OutsideTouchable and still nothing.

public class popUp extends PopupWindow implements ViewPager.OnPageChangeListener, 
    View.OnClickListener{

    public popUp{
          setContentView(view);
          setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
          setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
          setOutsideTouchable(true);
          setFocusable(true);
          showAtLocation(view, Gravity.CENTER, 0,0);
          setBackgroundDrawable(new ColorDrawable());
    }}

Activity

  @Override
    public void onBackPressed() {
        if(ViewPagerAdapter!=null){
            if (ViewPagerAdapter.popUp!= null && ViewPagerAdapter.popUp.isShowing())
                ViewPagerAdapter.popUp.dismiss();
             else
                super.onBackPressed();
            }
    }
Expiredmind
  • 788
  • 1
  • 8
  • 29

2 Answers2

0

Is this your total code? There is no popup window. Popup window means Alert Dialog according to my knowledge. And If I am not wrong your some where set your.

alartDialog.setCancelable(false);

remove that code you will be able to work with your back button. that code disable back button when showing the alert dialog.

Better you share your total code....

Arnab Kundu
  • 1,287
  • 2
  • 12
  • 17
  • https://developer.android.com/reference/android/widget/PopupWindow.html I called it by its type and I did not setCancelable anywhere in my code. The rest of code its quite extensive and It didnt concerns the issue – Expiredmind Oct 17 '16 at 13:08
0

You can try this...

 public class popUp extends PopupWindow implements View.OnClickListener{
 @Override
 public boolean onKey(View v, int keyCode, KeyEvent event) {
    if(keyCode== KeyEvent.KEYCODE_BACK){
        yourPopupWindow.dismiss();
    }
    return true;
 }

}

You have implemented View.OnClickListener which have onKey implemented method use that...

Arnab Kundu
  • 1,287
  • 2
  • 12
  • 17