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.