【发布时间】:2013-02-21 10:17:19
【问题描述】:
我在地图位于第二个位置的下拉导航活动中使用 Google Maps API V2。
我正在务实地添加地图,例如:
mMapFragment = supportMapFragment.newInstance();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.placeHolder, mMapFragment, TAG_MAP)
.commit();
我想获取 GoogleMap 对象,因为文档 https://developers.google.com/maps/documentation/android/map 说应该使用 mMapFragment.getMap() 完成,但它返回 null。
根据http://developer.android.com/reference/com/google/android/gms/maps/SupportMapFragment.html 如果 Fragment 没有经过 onCreateView 生命周期事件,则返回 null。
我如何知道片段何时准备就绪?
编辑:我发现了这个How do I know the map is ready to get used when using the SupportMapFragment?
覆盖 onActivityCreated 似乎是一个解决方案,但是我必须通过构造函数而不是使用 newInstance() 来实例化片段,这有什么区别吗?
【问题讨论】:
标签: android android-fragments google-maps-android-api-2