使PopupMenu工作

时间:2014-09-24 01:29:48

标签: android view popupmenu

我在如何实现此弹出菜单时遇到问题。我使用ListActivity,我不知道如何使这个弹出菜单工作。你能帮我解决这个问题吗?

public View getView(final int position, View v, ViewGroup parent){
        LayoutInflater inflater = getLayoutInflater();
        v = inflater.inflate(R.layout.list_item_albums, null);

        imgClick = (ImageView) v.findViewById(R.id.row_click_imageView1);
        imgClick.setOnClickListener(new View.OnClickListener(){

            public void onClick(View v){
                PopupMenu pop = new PopupMenu(AlbumsActivity.this,imgClick);
                pop.getMenuInflater().inflate(R.menu.menu,pop.getMenu());

                pop.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){

                    @Override
                    public boolean onMenuItemClick(MenuItem item){
                        Toast.makeText(AlbumsActivity.this,"text"+item.getTitle(),Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(AlbumsActivity.this,NexActivity.class);
                        startActivityForResult(intent, 2);
                        return true;
                    }
                });
                pop.show();
            }
        });
        return v;
    }

0 个答案:

没有答案