gpt4 book ai didi

android - Adapter getView() 中的 PopupMenu 不工作

转载 作者:太空狗 更新时间:2023-10-29 16:36:48 24 4
gpt4 key购买 nike

我正在使用自定义适配器并在 getView() 方法上添加此代码:

final ImageView popupMenu = (ImageView) v.findViewById(R.id.popupMenu);
popupMenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
popupMenu.setImageResource(R.drawable.ic_popup_menu_selected);
PopupMenu popup = new PopupMenu(context, view);
popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu pm) {
popupMenu.setImageResource(R.drawable.ic_popup_menu);
}
});
popup.show();
}
});

但是我得到这个错误: java.lang.RuntimeException:无法解析索引 6 处的属性

相同的代码适用于 ListItemClick(),但它在那里没有意义,因为它需要单击一次以设置并再次单击以触发 PopupMenu。

编辑:Logcat

11-02 17:58:51.276    1996-1996/com.android.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.android.example, PID: 1996
java.lang.RuntimeException: Failed to resolve attribute at index 6
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:603)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6423)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6591)
at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:735)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:679)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:62)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.support.v7.internal.view.menu.MenuPopupHelper$MenuAdapter.getView(MenuPopupHelper.java:363)
at android.support.v7.internal.view.menu.MenuPopupHelper.measureContentWidth(MenuPopupHelper.java:212)
at android.support.v7.internal.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:146)
at android.support.v7.internal.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:118)
at android.support.v7.widget.PopupMenu.show(PopupMenu.java:168)
at com.android.example.GetAdapter$listAdapter$1.onClick(GetAdapter.java:81)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

最佳答案

通过以下导入,我总是遇到错误:

import android.support.v7.widget.PopupMenu;

它适用于以下导入:

import android.widget.PopupMenu;

完整答案:stackoverflow.com/a/27826670/4548500

关于android - Adapter getView() 中的 PopupMenu 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26702540/

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