Popupmenu appearing at the top of the screen

Asked

Viewed 67 times

1

I did an implementation of a PopupMenu being called within a Adapter of a ListView, the mistake that this happening is that when I call the PopupMenu, the same is being displayed at the top of Activity. The correct is to display on the line I clicked from ListView.

Follows the code:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(resource, parent, false);
        }

        //Grava o context do aplicativo
        mContext = convertView.getContext();

        //Inicializando os componentes da item_atividade.xml
        ImageView ivIcone = (ImageView) convertView.findViewById(R.id.item_atividade_iv_icone);
        TextView tvID = (TextView) convertView.findViewById(R.id.item_atividade_tv_id);
        TextView tvNome = (TextView) convertView.findViewById(R.id.item_atividade_tv_titulo);
        TextView tvDetalhes = (TextView) convertView.findViewById(R.id.item_atividade_tv_descricao);

        //Inicializa os componentes de click
        llmenupopup = (LinearLayout) convertView.findViewById(R.id.item_atividade_ll_menu);
        ivMenupopup = (ImageView) convertView.findViewById(R.id.item_atividade_iv_menupopup);

        //Método de click do popup da listwiew
        llmenupopup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Menu popup
                ivMenupopup.setImageResource(R.drawable.ic_menupopup);
                final PopupMenu mPopupMenu = new PopupMenu(mContext, ivMenupopup);
                mPopupMenu.setGravity(Gravity.RIGHT);
                mPopupMenu.getMenuInflater().inflate(R.menu.list_atividades, mPopupMenu.getMenu());
  • Hello the problem has been solved as follows: //Menu popup ivMenupopup.setImageResource(R.drawable.ic_menupopup); final Popupmenu mPopupMenu = new Popupmenu(mContext, v);

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.