Create PopupMenu from menu id and action listener - Android User Interface

Android examples for User Interface:PopupMenu

Description

Create PopupMenu from menu id and action listener

Demo Code


import android.content.Context;
import android.support.v7.widget.PopupMenu;
import android.view.View;

public class Main{
    /***********************************************
     * Popup */* w  ww  .  j  a v a2  s.  c  o  m*/
     **********************************************/

    public static PopupMenu getPopupMenu(Context context, View anchor,
            int menuId,
            PopupMenu.OnMenuItemClickListener onMenuItemClickListener,
            PopupMenu.OnDismissListener onDismissListener) {
        PopupMenu popup;
        popup = new PopupMenu(context, anchor);
        popup.getMenuInflater().inflate(menuId, popup.getMenu());
        if (onMenuItemClickListener != null) {
            popup.setOnMenuItemClickListener(onMenuItemClickListener);
        }
        if (onDismissListener != null) {
            popup.setOnDismissListener(onDismissListener);
        }
        return popup;
    }
}

Related Tutorials