0

I have a listview that is registeredforcontextmenu.

I am trying to change the default font for the context menu using spannablestring and it is ok. But when i click on the menu, the app crashes. this is the 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)

and this is my 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);
    }

what is wrong? I really need to change the context menu font.

SMahdiS
  • 930
  • 13
  • 33
  • Maybe this can help you- http://stackoverflow.com/questions/7658725/android-java-lang-illegalargumentexception-invalid-payload-item-type – amit singh Jan 23 '14 at 10:32

1 Answers1

0

I have the same problem. Override onMenuItemSelected and don't use onContextItemSelected.

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// THIS FIXED BUG Android 4.0.3 ON LG DEVICES
/* Your code here */        
return false;
}
AC1D
  • 248
  • 5
  • 16