【问题标题】:Android : Support MapFragment Returns nullAndroid:支持 MapFragment 返回 null
【发布时间】:2014-10-21 10:13:39
【问题描述】:

我已将 android SDK 更新到 5.0,但我之前的项目无法运行(在 4.4.2 中正常运行)。

我有一个扩展片段的类

public class MapFragment extends Fragment{
//
}

在这个课程中,我使用谷歌支持的 mapfragment 扩展了一个布局

<?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 中对我有用,但更新后出现了一些问题......

有没有人找到解决办法...

【问题讨论】:

    标签: android google-maps android-fragments supportmapfragment


    【解决方案1】:

    我找到了答案,它对我有用

    不是这个

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

    我变了

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 2021-07-07
      • 2012-06-22
      • 2012-05-28
      相关资源
      最近更新 更多