0

I was having some problem with popup window in Android. What I am trying to do is when user first click on the button, popup window will show. If the pop up window is shown and user click on the button again, the popup will be hidden. Here is my XML for the popup window:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llAttendeeList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" 
android:background="#000000"
>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="HELLO" />

</LinearLayout>

And the codes where button on click, it will execute this method:

private void openPopUp(){
    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getBaseContext().getSystemService(
                    context.LAYOUT_INFLATER_SERVICE);
    View popupView = layoutInflater.inflate(
            R.layout.event_attendee_pop, null);
    llAttendeeList = (LinearLayout) popupView
            .findViewById(R.id.llAttendeeList);
    final PopupWindow popupWindow = new PopupWindow(popupView,
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    popupWindow.setOutsideTouchable(true);

    popupWindow.setTouchInterceptor(new OnTouchListener() { 
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_OUTSIDE) 
                    {
                        popupWindow.dismiss();
                        return true;
                    }
                    return false;
                }
            });
    popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
}

However, when user first click on the button, the popup did appeared. But when I clicked outside the popup, it does not dismiss. Any ideas?

Thanks in advance.

2 Answers2

0

I figured out I've to set this to popup window:

popupWindow.setOutsideTouchable(true);
    popupWindow.setBackgroundDrawable(new ColorDrawable());
shaiban
  • 331
  • 5
  • 12
-1

Add popupWindow.setContentView(popupView) and try again

Nodlee
  • 69
  • 1
  • 5
  • Do you have any ideas how to set the pop up just below the action bar with a marginTop? –  Dec 27 '14 at 03:40
  • Any ideas? I cant set it to the position that I wanted –  Dec 27 '14 at 04:16