我有一个回收站视图和卡视图。卡布局有3个点,单击这些点将显示弹出菜单。一切正常,但是有一个小问题。如果单击顶部卡,则在回收者视图的底部显示弹出菜单。如果单击中间卡,则弹出菜单将显示在活动的左上方,依此类推。我希望,如果按下card_1的弹出菜单,它应该显示在card_1上,并且类似地,弹出菜单应该显示在它们各自的卡上。我不知道问题出在哪里。请帮忙!!!
这是菜单布局menu_options.xml
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="@+id/menu1"
android:title="Edit " />
<item
android:id="@+id/menu2"
android:title="Delete " />
这里是显示菜单的方法。它在CardViewAdapter中用于我的Recycler View。
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
...
threeDots = (TextView)cardView.findViewById(R.id.options);
threeDots.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popupMenu = new PopupMenu(context, threeDots);
popupMenu.inflate(R.menu.menu_options);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.menu1: int pos = holder.getAdapterPosition();
onEdit(pos);
break;
case R.id.menu2: Toast.makeText(context, "Swipe LEFT to delete the card", Toast.LENGTH_LONG)
.show();
break;
}
return false;
}
});
popupMenu.show();
}
});
}