1
votes

Hi i am trying to inflate or change menu from child fragment , but not able to do so. The flow is like this .

If I try to inflate menu from activity (Main)--- work fine. if i try to infalte menu from fragment (SecondFrag)----work fine if i try to inflate menu from child fragment of(SecondFrag)----do not work

Sample Code is like this

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    Log.d("It has option mener of not", ""+hasOptionsMenu());
}




@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //super.onCreateOptionsMenu(menu, inflater);
    Log.d("Option Menu", "Activity Option Menu");
    mActivity.getSupportMenuInflater().inflate(R.menu.deal_detaisl, menu);
    Log.d("Option Menu", "Activity Option Menu");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.deal_loc:
        mActivity.showMapFragment();
        break;

    case R.id.deal_loc_route:
        mActivity.showMapRoute();
        break;
    }
    return false;
}
1
mActivity.getSupportMenuInflater().inflate(R.menu.deal_detaisl, menu); is this line not working? Think I misunderstood your question.Carnal
Why don't you use the inflater you get from the method?Carnal
remove 'targetSdkVersion' from manifestSino Raj

1 Answers

1
votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.deal_detaisl, menu);
    super.onCreateOptionsMenu(menu, inflater);
}

This should work for you, try it.

Edit: You should create a custom Fragment and make the fragments extend that custom Fragment. Then in your Activity for onCreateOptionsMenu you can get the current Fragment and call a public method for inflating a menu (call it whatever). After a chat discussion, your problem was solved.