0

I'm trying to create a menu with TabHost. Options:

  • Tab1: no items
  • Tab2: one item

I've done it with setVisible true or false. But my problem is that the menu does not appear in Tab2 when I haven't items in Tab1. If I put items to Tab1 works ok.

I only use onPrepareOptionsMenu() and onOptionsItemSelected(). I haven't onCreateOptionsMenu() and invalidateOptionsMenu();

What is the problem?

public boolean onPrepareOptionsMenu(Menu menu) {

    menuItemActualizar = menu.findItem(R.id.menuOpcActualizar);

    switch (tabs.getCurrentTab()) {
    case 0:
        menuItemActualizar.setVisible(false);
        break;

    case 1:
        menuItemTipoMapa.setVisible(true);
        break;

    default:
        menuItemActualizar.setVisible(false);
        break;
    }

    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

        case R.id.menuOpcActualizar:

            ...

            return true;


        default:
            return super.onOptionsItemSelected(item);
    }
}
user4152
  • 241
  • 5
  • 16

1 Answers1

0

My problem is solved with:

public void onTabChanged(String tabId) {

    ActivityCompat.invalidateOptionsMenu((Activity)context);

    if(tabId.equals("mitab1")) {        

    } else if(tabId.equals("mitab2")) {


    }
}
user4152
  • 241
  • 5
  • 16