Question

Here is the code in my fragment

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.e("aaa", "ee");
        switch (item.getItemId()) {
        case R.id.edit:
            Log.e("sssssss","SSSSSSSSSSSSSSs");
            Intent editIntent = new Intent(getActivity(),
                    EditCustomerProfile.class);
            //startActivityForResult(editIntent, EditProfile);
            startActivity(editIntent);
            break;
        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }

I can see the menu item in my action bar.

I inflate the menu like this:

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        int currentTab = mViewPager.getCurrentItem();
        if (currentTab == 1) {
            menu.clear();
            inflater.inflate(R.menu.all_addresses, menu);
        } else if (currentTab == 0) {
            menu.clear();
            inflater.inflate(R.menu.profile, menu);
        }
        return super.onPrepareOptionsMenu(menu);
    }

I am talking about profile menu

but when i click on the edit, nothing happened, even the log is not working

Was it helpful?

Solution

It appears that you're creating your menu through your activity, but are trying to intercept menu item selection in your fragment.

In order for the fragment to be included in the call stack of onOptionItemSelected(), you should make ensure that the fragment has called hasOptionsMenu(true) in its respective onCreate().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top