安卓:支持MapFragment则返回nullMapFragment、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...

我已经在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);
阅读全文

相关推荐

最新文章