安卓:支持MapFragment则返回null [英] Android : Support MapFragment Returns null

查看:107
本文介绍了安卓:支持MapFragment则返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Android SDK更新到5.0,我的previous项目不是它的工作(这在4.4.2工作正常)。

I have updated the android SDK to 5.0 and my previous project is not working on it(which worked correctly in 4.4.2).

我有延伸片段的类

public class MapFragment extends Fragment{
//
}

在这个类我已经膨胀与谷歌的支持mapfragment布局

In this class i have inflated a layout with google support 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>

当我这样做在我的code将其返回null

When i do this in my code it return null

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

这同一条线路的Andr​​oid4.4.2为我工作,但之后选择更新有一些问题...

This same line worked for me in Android4.4.2 but after updation there is some problem...

做任何人找到了解决办法...

Do anyone found the solution...

推荐答案

我已经找到了答案,它为我的作品

I've found the answer and it works for me

取而代之的是

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

我已经改变为

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

这篇关于安卓:支持MapFragment则返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆