Could anyone please tell me that how is it possible to show and hide the same popup window using a single button.
suggestions welcome.
Popup means that when i clicked on a menu button it showing a popup window which contains the listview and when i clicked on the menu button again and touches anywhere on the screen,the popwindow should disappear.
I use the bellow code to do that. In your case the menuButton is your single button and content is your listview. The anchor can be the menuButton itself or another View.
public static void setupMenuButton(View menuButton, View content, final View anchor) {
    PopupWindow popup;
    menuButton.setOnClickListener(v -> {
        if (popup == null) {
            popup = new PopupWindow(content, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            popup.setOutsideTouchable(true);
        }
        if (popup.isShowing()) popup.dismiss();
        else popup.showAsDropDown(anchor);
    });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With