So my pop up menu not wants to show when i click on it. I don’t get any errors, I think I need to add some more lines of code. I just don’t know what? Below you can see the code of my adapter
public View findViewById(int position) { View view = findViewById(R.id.textViewOptions); View textViewOptions = null; textViewOptions.setOnClickListener(new View.OnClickListener() { ViewHolder holder; @Override public void onClick(View view) { //creating a popup menu PopupMenu popup = new PopupMenu(context, holder.textViewOptions); //inflating menu from xml resource popup.inflate(R.menu.chatmenu); //adding click listener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.BlockUser: //handle menu1 click return true; case R.id.MuteNotificationsCH: //handle menu2 click return true; } return true; } }); popup.show(); } }); return view; }
And this is my xml (“The place where i click and not seeing the pop up menu”)
<TextView android:id="@+id/textViewOptions" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginTop="16dp" android:layout_marginEnd="12dp" android:layout_marginRight="12dp" android:text="⋮" android:clickable="true" android:textAppearance="?android:textAppearanceLarge" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" />
Advertisement
Answer
So here is how I implemented a popup menu. This may assist you in locating the problem in your code.
holder.imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popupMenu = new PopupMenu(UserDetailsActivity.this, holder.imageButton); popupMenu.inflate(R.menu.popup_menu); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.popupCall: //call user return true; case R.id.popupMail: //mail user return true; default: return false; } } }); popupMenu.show(); } });