所以我的弹出菜单不想在我点击它时显示。我没有收到任何错误,我想我需要添加更多代码行。我只是不知道什么?下面你可以看到我的适配器的代码
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;
}
这是我的 xml(“我点击但没有看到弹出菜单的地方”)
<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" />
答案 0 :(得分:0)
这就是我实现弹出菜单的方法。这可能有助于您定位代码中的问题。
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();
}
});