我已经将android SDK更新到5.0,而我先前的项目无法在其上运行(在4.4.2中正常运行)。

我有一个扩展片段的类

public class MapFragment extends Fragment{
//
}


在这一节课中,我用Google支持的地图片段夸大了版式

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_tile_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible" >

    <RelativeLayout
        android:id="@+id/full_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />

        <Textview
            <!-- dfh
            fgh -->
        />

    </RelativeLayout>

</RelativeLayout>


当我在我的代码中执行此操作时,它返回null

    SupportMapFragment fragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);


同一行在Android4.4.2中对我有用,但更新后出现了一些问题...

有谁找到解决方案...

最佳答案

我找到了答案,对我有用

代替这个

 SupportMapFragment fragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);


我已更改为

SupportMapFragment  fragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);

关于android - Android:支持MapFragment返回null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26484217/

10-13 21:41