I'm now following a viewpager guide in
http://developer.android.com/training/implementing-navigation/lateral.html
And I met a serious problem.
As I wrote in title, I tried to put the Google map v2 in each fragment of viewpager and I met this error. (Two ScreenSlidePageFragment gets generated at once and it inflates map for each them.)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f0a0059, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
at android.app.Activity.onCreateView(Activity.java:4835)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.maurat.trackuz.ScreenSlidePageFragment.onCreateView(ScreenSlidePageFragment.java:39)
I think because this viewpager loads 2 pages at once at the first time and the map fragment's id gets duplicated.
ScreenSlidePagerAdapter
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Log.d(TAG, "getItem " + position);
return new ScreenSlidePageFragment();
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
ScreenSlidePageFragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
Log.d(TAG, "onCreateView");
ViewGroup view = (ViewGroup) inflater.inflate(
R.layout.fragment_screen_slide_page,
container,
false);
return view;
}
fragment_screen_slide_page.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C7F464">
<fragment
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
So I've found and tried several solution but didn't found the solution for now. https://stackoverflow.com/a/14929151/1122517 https://stackoverflow.com/a/14695397/1122517
Now I'm finding a solution such like making a fragment programmatically.
Please help me.