private void toggleMapAndList() { state = state == State.MAP ? State.LIST : State.MAP; if (state == State.LIST) { if (mapFragment != null) { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.hide(mapFragment).commit(); } recyclerView.setVisibility(View.VISIBLE); currentPlaceCardView.setVisibility(View.VISIBLE); } if (state == State.MAP) { if (mapFragment == null) { mapFragment = SupportMapFragment.newInstance(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); transaction.replace(R.id.place_search_map_placeholder, mapFragment); transaction.commit(); mapFragment.getMapAsync(this); } else { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.show(mapFragment).commit(); } recyclerView.setVisibility(View.INVISIBLE); currentPlaceCardView.setVisibility(View.INVISIBLE); } displayPlaces(placesToDisplay); }
@Override public Fragment getItem(int position) { switch (position) { case 0: case 1: return new TextFragment(); case 2: return SupportMapFragment.newInstance(); default: return null; } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // It isn't possible to set a fragment's id programmatically so we set a tag instead and // search for it using that. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG); // We only create a fragment if it doesn't already exist. if (mapFragment == null) { // To programmatically add the map, we first create a SupportMapFragment. mapFragment = SupportMapFragment.newInstance(); // Then we add it using a FragmentTransaction. FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(android.R.id.content, mapFragment, MAP_FRAGMENT_TAG); fragmentTransaction.commit(); } mapFragment.getMapAsync(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready // to be used. SupportMapFragment mapFragment = SupportMapFragment.newInstance(); getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, mapFragment).commit(); mapFragment.getMapAsync(this); }
private void init() { Log.d("NGVL", "init::BEGIN"); SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(TAG); if (fragment == null) { fragment = SupportMapFragment.newInstance(); getSupportFragmentManager() .beginTransaction() .replace(R.id.map, fragment, TAG) .commit(); } mGoogleApiClient.connect(); Log.d("NGVL", "init::END"); } }
mapFragment = SupportMapFragment.newInstance(); getSupportFragmentManager().beginTransaction().replace(R.id.map, mapFragment).commit();