我有一个listforcontextmenu的listview。
我正在尝试使用spannablestring更改上下文菜单的默认字体,这没关系。但是当我点击菜单时,应用程序崩溃了。这是logcat:
01-23 13:46:29.400: E/AndroidRuntime(18761): FATAL EXCEPTION: main
01-23 13:46:29.400: E/AndroidRuntime(18761): java.lang.IllegalArgumentException: Invalid payload item type
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.util.EventLog.writeEvent(Native Method)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.app.Activity.onMenuItemSelected(Activity.java:2629)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:4177)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:193)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:934)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.widget.AbsListView.performItemClick(AbsListView.java:1287)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3078)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.widget.AbsListView$1.run(AbsListView.java:4159)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.os.Handler.handleCallback(Handler.java:615)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.os.Handler.dispatchMessage(Handler.java:92)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.os.Looper.loop(Looper.java:137)
01-23 13:46:29.400: E/AndroidRuntime(18761): at android.app.ActivityThread.main(ActivityThread.java:4947)
01-23 13:46:29.400: E/AndroidRuntime(18761): at java.lang.reflect.Method.invokeNative(Native Method)
01-23 13:46:29.400: E/AndroidRuntime(18761): at java.lang.reflect.Method.invoke(Method.java:511)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-23 13:46:29.400: E/AndroidRuntime(18761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-23 13:46:29.400: E/AndroidRuntime(18761): at dalvik.system.NativeStart.main(Native Method)
这是我的oncreatecontextmenu:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
SpannableString s;
s = new SpannableString("item1");
s.setSpan(new MainActivity.TypefaceSpan(getActivity(), "tahoma.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
menu.add(s);
}
有什么不对?我真的需要更改上下文菜单字体。
答案 0 :(得分:0)
我有同样的问题。覆盖onMenuItemSelected并且不使用onContextItemSelected。
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// THIS FIXED BUG Android 4.0.3 ON LG DEVICES
/* Your code here */
return false;
}