:的PopupMenu()我使用自定義適配器,並添加上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: Failed to resolve attribute at index 6
相同的代碼工作onListItemClick(),但它沒有意義,因爲它需要點擊一次設置,再次點擊觸發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)
你能發佈logcat錯誤? – 2014-11-02 19:03:06
@GoranHoriaMihail完成。 – Shixons 2014-11-03 00:52:39
GetAdapter.java:81這行是它崩潰的地方。這條線是什麼? – 2014-11-03 07:12:08