【发布时间】:2014-08-13 23:09:12
【问题描述】:
我看过this 和类似的帖子。
在我看来,我所做的一切都是正确的。
还是,
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);`
返回 NULL。
activty_map.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
/>
<Button
android:id="@+id/startgeo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Geo"
android:background="@android:color/transparent"
android:layout_gravity="right"/>
</FrameLayout>
我的活动中的代码:
setContentView(R.layout.activty_map);
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map); //RETURNS NULL !!!
map = mapFrag.getMap();
【问题讨论】:
-
我认为 getMap() 可能返回 null,确定不是吗?
-
如何添加片段?
-
@nikis 在这种情况下我需要添加片段吗?
标签: android google-maps android-fragments