Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PopupMenu equivalent in ActionBarSherlock

What is the PopupMenu equivalent in ActionBarSherlock? I can't seem to find it. Its API 11, why is it absent?

like image 685
Taranfx Avatar asked Aug 25 '12 19:08

Taranfx


1 Answers

The Class MenuPopupHelper pretty much does the job. I didn't find an easy way to listen for Item Clicks though, so I implemented this class that derives from MenuPopupHelper:

public class MenuPopup extends MenuPopupHelper {

    OnMenuItemClickListener onMenuItemClickListener;

    public MenuPopup(Context context, MenuBuilder menu, View anchorView) {
        super(context, menu, anchorView);
    }

    public void setOnMenuItemClickListener(
            OnMenuItemClickListener onMenuItemClickListener) {
        this.onMenuItemClickListener = onMenuItemClickListener;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        super.onItemClick(parent, view, position, id);
        if (onMenuItemClickListener != null)
            onMenuItemClickListener.onMenuItemClick(position);
    }

    public interface OnMenuItemClickListener{
        public void onMenuItemClick(int itemID);
    }
}
like image 200
Georg Avatar answered Oct 25 '22 23:10

Georg