I'm making an Android app to load data into a RecyclerView with an ImageView inside as the overflow button. When users click it, a PopupMenu is displayed with options to choose. I had managed to show it but the position does not seem right. Please look at the screenshots.
Only the first two items seem OK. Here are the source code:
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(context, view);
final Menu menu = popupMenu.getMenu();
popupMenu.getMenuInflater().inflate(R.menu.menu_item_action, menu);
popupMenu.setOnMenuItemClickListener(onMenuItemClickListener);
switch (Global.listMode) {
case Global.LIST_STYLE_NORMAL: {
menu.findItem(R.id.action_delete).setVisible(false);
break;
}
case Global.LIST_STYLE_FAVORITE: {
menu.findItem(R.id.action_add_to_favorite).setVisible(false);
break;
}
case Global.LIST_STYLE_WATCH_LIST: {
menu.findItem(R.id.action_add_to_watch_list).setVisible(false);
break;
}
case Global.LIST_STYLE_DOWNLOAD: {
menu.findItem(R.id.action_download).setVisible(false);
break;
}
}
itemPosition = (int) view.getTag(R.id.tag_item_position);
popupMenu.show();
}
});
Can you guys point me out the issue, I had took hours for searching but still found nothing up now.
P/S: The clicked button is marked with red circle.
Any helps would be appreciated!
Luckily, I've just found the way to solve the problem:
android.widget.PopupMenu
not android.support.v7.widget.PopupMenu
final PopupMenu popupMenu = new PopupMenu(context, view);
with final PopupMenu popupMenu = new PopupMenu(context, v);
Honestly, I don't know why, just try it and voila!
I'm not pretty sure but seems that a similar problem is duscussed here and it already has an accepted answer. Hope it will help you with your problem. Just stumbled upon your question and saw the topic discussed in the link and thought maybe it might be helpful for you too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With