Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action overflow menus for elements of a list view

Tags:

android

view

menu

The overflow actions menu looks exactly like what I need, but it seems to only work within action bars. However, I'd like this kind of three-dots-menu on the right side of each element of a list view.

Action overflow menu outside of action bar

Is there a built-in view that can be used for this?

like image 858
danijar Avatar asked Dec 12 '15 15:12

danijar


1 Answers

You can use an ImageView and a PopupMenu.

Context context = ...
ImageView overflow = ...

PopupMenu popup = new PopupMenu(context, overflow);
popup.inflate(R.menu.your_menu_resource);
popup.setOnMenuItemClickListener(...);

overflow.setOnClickListener(new View.OnClickListener() {
        @Override
        public final void onClick(View v) {
            popup.show();
        }
}
overflow.setOnTouchListener(popup.getDragToOpenListener());
like image 142
RussHWolf Avatar answered Sep 27 '22 21:09

RussHWolf