public void detectFragment() {
    FragmentB fragment = (FragmentB) getFragmentManager().findFragmentById(R.id.fragB);
    if (fragment == null || !fragment.isInLayout()) {
      TextView tv = (TextView) findViewById(R.id.buttonFragA);
      tv.setText("PORTRAIT");

    } else {
      TextView tv = (TextView) findViewById(R.id.buttonFragA);
      tv.setText("LAND");
    }
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_fragment_a) {
      getSupportFragmentManager()
          .beginTransaction()
          .replace(R.id.main_container, FragmentA.newInstance("test", "test"))
          .commit();
      return true;
    }
    if (id == R.id.action_fragment_b) {
      getSupportFragmentManager()
          .beginTransaction()
          .replace(R.id.main_container, FragmentB.newInstance("test", "test"))
          .commit();
      return true;
    }

    return super.onOptionsItemSelected(item);
  }