Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the position of Pop Up Menu?

Tags:

android

I am using the PopupMenu ,i have to fix the position of the pop up menu below the buttton which i click,but it show on the above the my button below is the code which i do.

private final static int ONE = 1;
private final static int TWO = 2;
private final static int THREE = 3;

PopupMenu popupMenu = new PopupMenu(context, convertView.findViewById(R.id.txtOverflowIconList_item_Egov));

popupMenu.getMenu().add(Menu.NONE, ONE, Menu.NONE, "Item 1");
popupMenu.getMenu().add(Menu.NONE, TWO, Menu.NONE, "Item 2");
// popupMenu.getMenu().add(Menu.NONE, THREE, Menu.NONE, "Item 3");

popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {

        switch (item.getItemId()) {
            case ONE:
                Toast.makeText(context, "first ", 100).show();
                break;
            case TWO:
                Toast.makeText(context, "Two ", 100).show();
                break;
        }
        return false;
    }
});


holder.txtOverflowIcon.setOnClickListener(new OnClickListener() {
    public void onClick(View arg0) {
        popupMenu.show();
    }
});

Below is th output what i get:

this is output what i get.

please help me.

like image 376
Suraj Avatar asked Jan 31 '26 17:01

Suraj


1 Answers

I could fix that problem. The PopupMenu will reveal like the one in the ActionBar: https://stackoverflow.com/a/29702608/1185087

like image 75
user1185087 Avatar answered Feb 02 '26 09:02

user1185087



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!