fragmentTransaction.add(R.id.mapView,mMapFragment)不起作用

时间:2015-11-10 13:26:50

标签: android fragmenttransaction

如何在mapView中添加mapFragment? 为什么这不起作用? 我该怎么办呢?)?

public class MapsActivity extends FragmentActivity {
  // ..............................................

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
MapFragment mMapFragment = MapFragment.newInstance();
fragmentTransaction.add(R.id.mapView, mMapFragment);
fragmentTransaction.commit();

XML     

        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MapsActivity"
        tools:layout="@layout/activity_maps"
        class="com.google.android.gms.maps.SupportMapFragment"/>

无法解析方法添加

1 个答案:

答案 0 :(得分:-1)

替换

MapFragment mMapFragment = MapFragment.newInstance();

MapFragment mMapFragment = new MapFragment();