【发布时间】:2015-02-23 14:20:46
【问题描述】:
当我第一次调用片段时我可以访问地图,但是当我第二次调用片段时,它给了我这个由错误引起的:
12-26 09:36:41.306: E/AndroidRuntime(28156): Caused by: java.lang.IllegalArgumentException: Binary XML file line #164: Duplicate id 0x7f090012, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
我在片段类的 onCreateView() 中创建内部地图片段:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Defines the xml file for the fragment
View view = inflater.inflate(R.layout.howtogo_fragment, container,
false);
if(map==null)
map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
}
这是我的片段的布局:
<LinearLayout>
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
【问题讨论】:
-
map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
-
在片段的onDestroyView()中移除地图片段。并在 onCreateView 中重新初始化地图。不喜欢添加片段事务。
-
#Figen Güngör 你解决了吗?
标签: android google-maps android-fragments dictionary fragment