Note that there are some explanatory texts on larger screens.

plurals
  1. POSwitching from Map fragment to another Fragment and back
    primarykey
    data
    text
    <p>I have a fragment activity that switches fragments on button click.<br> The two fragments that I switch are:</p> <ol> <li>Google map android v2 fragment</li> <li>Another fragment with a text view</li> </ol> <p>This is how I switch the fragments:</p> <pre><code>public void onClick(View v) { FragmentManager fm = getSupportFragmentManager(); if(tv.getText().toString().equalsIgnoreCase("Click ME!!")){ tv.setText("MAP"); if (fm != null) { if(map == null){ map = new Map(); } FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.lay_contaier, map); ft.commit(); } } else{ tv.setText("Click ME!!"); if (fm != null ){ FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.lay_contaier,new empty()); ft.commit(); } } } </code></pre> <p>This s my Maps Fagment code</p> <pre><code> public class Map extends Fragment implements OnMarkerClickListener, OnInfoWindowClickListener, OnMarkerDragListener { private static final LatLng PERTH = new LatLng(-31.952854, 115.857342); private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689); private GoogleMap mMap; private Marker mPerth; private Marker mSydney; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_main,null); return view; } </code></pre> <p>activity_mail.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" class="com.google.android.gms.maps.SupportMapFragment"/&gt; </code></pre> <p>But every time I swich back to the Map fragment the Application crashes. How should I make this code right?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload