I made an implementation of a PopupMenu
being called inside a Adapter
of a ListView
, the error that is happening is that when I call PopupMenu
, it is being displayed at the top of Activity
. The correct one is to display on the line that I clicked on ListView
.
Follow 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());