0

I have onOptionsItemSelected(MenuItem item) in my fragment. Now I'm forced to use Android-ActionItemBadge library(https://github.com/mikepenz/Android-ActionItemBadge), to add the ActionBar Notification Count. so I added the piece of code in my Fragment.

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            //Inflating the Menu
                inflater.inflate(R.menu.refresh_menu, menu);

        //inflating Notification Icon
        if (badgeCount > 0) {
            ActionItemBadge.update(getActivity(), menu.findItem(R.id.badge),
                    FontAwesome.Icon.faw_android, ActionItemBadge.BadgeStyle.DARKGREY, badgeCount);
        } else {
            ActionItemBadge.hide(menu.findItem(R.id.badge));
        }
}

But this Optionsitemselected return the value to my Activity but not in to my Fragment. any Idea? I want to Handle this Optionsitemselected in my Fragment.

Vrangle
  • 323
  • 5
  • 13

1 Answers1

2

In your fragment you need to call:

setHasOptionsMenu(true);

Edit:

Since this custom ActionBar item isn't providing the calls to your fragment you can simply do it manually:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_search: // Your item id
            Fragment f = getFragmentManager().findFragmentById(R.id.fragment_container);
            f.onOptionsItemSelected(item);
            break;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
Simas
  • 43,548
  • 10
  • 88
  • 116
  • I enabled and other options are working fine. Only this ActionItemBadge is handling the clickevent in MainActivity. – Vrangle Feb 13 '15 at 18:34
  • @Vrangle I see. You could just do it manually then, as in my updated answer. – Simas Feb 13 '15 at 18:42
  • Works great Cheers. Little More clear so that others can understand. I have implemented this code in my main Activity and transfer the call to my Fragments and My Fragments have it's own onOptionsItemSelected(MenuItem item) method to handle it. Well done user3249477 – Vrangle Feb 13 '15 at 18:54