I got a problem in changing mapfragments to other fragments. (Listfragment or text)
When I use fragmenttransaction to a fragment with only text. The map is still there, and new fragment is over the map. I cannot remove the map.
I searched it, but did not find good approach.
Can someone provide some ideas?
This is the main activity.that extends Activity
enter code here
protected void onCreate(Bundle savedInstanceState) {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager myfm = getFragmentManager();
FragmentTransaction ft = myfm.beginTransaction();
mymap = new StartFragment();
ft.add(R.id.map, mymap);
ft.commit();
This is the fragment in activity_main;
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_below="@+id/Deerfield"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This is the start_fragment class
public class StartFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map_layout,null);
return view;
}
}
Then the map_layout
<?xml version="1.0" encoding="utf-8"?>
<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.MapFragment"/>
Thank you!