sherlock actionbar menu

Posted by user1647443 on Stack Overflow See other posts from Stack Overflow or by user1647443
Published on 2012-09-04T22:03:38Z Indexed on 2012/09/05 3:38 UTC
Read the original article Hit count: 221

Filed under:
|

I am trying to setup a menu programatically and my method gets com.actionbarsherlock.view.Menu menu as a parameter. As I want to change the styling of the menu item I am trying to setup a SpannableString spannable and pass it to add. menu.add(0, MENU_ABOUT, 0, spannable); This is causing a crash only in ICS when I cick that menu item. Any ideas if I am missing something. Thanks Here is the code I am trying and it crashes when I run the app and select "About Application". FYI, I am using SpannableString because I want to add some styling and color to the menu item. The crash does NOT happen if I use a regular string, but then I cant do styling

    public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu)
{
    SpannableString spannable = new SpannableString("About Application");
    menu.add(0, MENU_ABOUT, 0, spannable);
    return true;
}

Here is the stack trace:

    09-05 02:25:32.849: E/AndroidRuntime(684): FATAL EXCEPTION: main
    09-05 02:25:32.849: E/AndroidRuntime(684): java.lang.IllegalArgumentException:  Invalid payload item type
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.util.EventLog.writeEvent(Native Method)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.app.Activity.onMenuItemSelected(Activity.java:2501)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:351)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:950)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:163)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.widget.AdapterView.performItemClick(AdapterView.java:292)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.widget.AbsListView.onTouchEvent(AbsListView.java:3180)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.View.dispatchTouchEvent(View.java:5541)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.View.dispatchPointerEvent(View.java:5721)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.os.Handler.dispatchMessage(Handler.java:99)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.os.Looper.loop(Looper.java:137)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at android.app.ActivityThread.main(ActivityThread.java:4424)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at java.lang.reflect.Method.invokeNative(Native Method)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at java.lang.reflect.Method.invoke(Method.java:511)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    09-05 02:25:32.849: E/AndroidRuntime(684):  at dalvik.system.NativeStart.main(Native Method)

Thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about actionbarsherlock