单击intent和getIntent时弹出菜单

时间:2014-09-25 14:36:11

标签: android android-intent position popupmenu

我尝试使用带有弹出菜单的列表项在另一个活动上显示内容。因此,如果我点击其中一个项目的弹出菜单,它必须返回/显示该项目被点击的另一个活动。但我的问题是,如果我用弹出菜单点击该项目,它会显示另一个值。我不知道如何解决这个问题。有什么想法?非常感谢。

This is the item's popup menu to be clicked

This is the result when item's popupmenu is clicked.

这是我的popupmenu代码:

public void popup(View v){
        showPopupMenu(v);
    }
    private void showPopupMenu(View v){
        PopupMenu pop = new PopupMenu(CompanyActivity.this, v);
        pop.getMenuInflater().inflate(R.menu.menu,pop.getMenu());

        pop.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem arg0) {
                Intent i = new Intent(getApplicationContext(), MainActivity.class);

                String album_name = ((TextView) findViewById(R.id.album_name)).getText().toString();
                i.putExtra("album_name", album_name);
                startActivity(i);
                return true;
            }
            });
        pop.show();
    }

0 个答案:

没有答案