gpt4 book ai didi

java - com.android.internal.view.menu.MenuBuilder 无法在 android 中转换为 android.support.v7.view.menu.MenuBuilder

转载 作者:行者123 更新时间:2023-11-30 10:22:06 26 4
gpt4 key购买 nike

我在 ActivityRecyclerViewAdapter 中创建了一个回收器 View

以下是我在onBindViewHolder()中编写的代码 fragment :

PopupMenu popupMenu = new PopupMenu(activity,holder.ivEventShare);
popupMenu.getMenuInflater().inflate(R.menu.item_event,popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.action_item_event_share:
Toast.makeText(activity, "This Item will be shared", Toast.LENGTH_SHORT)show();
break;
}
return true;
}
});

popupMenu.show();
MenuPopupHelper helper = new MenuPopupHelper(activity, (MenuBuilder) popupMenu.getMenu(),v);
helper.setForceShowIcon(true);
helper.setGravity(Gravity.END);
helper.show();

我已经创建了 PopUpMenu,我希望它显示带有图标的菜单。

但它显示以下错误:

com.android.internal.view.menu.MenuBuilder cannot be cast to android.support.v7.view.menu.MenuBuilder

在这一行中:

MenuPopupHelper helper = new MenuPopupHelper(activity, (MenuBuilder) popupMenu.getMenu(),v);

如有任何帮助,我们将不胜感激。

最佳答案

import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.view.menu.MenuPopupHelper;
import android.support.v7.widget.PopupMenu;

//enter code here

imagePostShare.setOnClickListener(new View.OnClickListener() {

@SuppressLint("RestrictedApi")
@Override
public void onClick(View v) {
popup = new PopupMenu(mContext, v);
popup.getMenuInflater().inflate(R.menu.share_menu, popup.getMenu());

// popup.show();
MenuPopupHelper menuHelper = new MenuPopupHelper(mContext, (MenuBuilder) popup.getMenu(),v);
menuHelper.setForceShowIcon(true);
menuHelper.show();

popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
int id = menuItem.getItemId();

if (id == R.id.shareAsPost) {
String postId = item.getSharedPostId();
Call<PostShareItem> call = webService.getPostDetails(deviceId,
profileId, token, userIds, postId);
sendShareItemRequest(call);
}

if (id == R.id.shareFacebook) {}
if (id == R.id.shareTwitter) {
Toast.makeText(App.getAppContext(), "Removed : ",
Toast.LENGTH_SHORT).show();
}

if (id == R.id.copyLink) {}
return true;
}
});
}
});

关于java - com.android.internal.view.menu.MenuBuilder 无法在 android 中转换为 android.support.v7.view.menu.MenuBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47482970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com