Java tutorial
//package com.java2s; import android.app.Dialog; import android.content.DialogInterface; import android.view.View; import android.widget.PopupWindow; public class Main { public static void toggle(PopupWindow window, View view) { if (null != window) { if (window.isShowing()) window.dismiss(); else window.showAsDropDown(view); } } public static void dismiss(Dialog dialog) { if (null != dialog) dialog.dismiss(); } public static void dismiss(DialogInterface dialog) { if (null != dialog) dialog.dismiss(); } public static void dismiss(PopupWindow window) { if (null != window) window.dismiss(); } }