I'm running into a (I'm sure) silly problem and could use another set of eyes.
I have an app that requires GoogleMaps be shown in several places in the app. I have it successfully shown in my main activity, all Play libraries are in place, V2 key is all set-up, etc.
My (truncated) mapview.xml
looks like:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
As I said, on the main activity, I can set the contentView correctly and draw a map, no problem.
However, on a different activity, I'm implementing tabs:
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Add tabs
actionBar.addTab(actionBar.newTab().setText(R.string.map).setTabListener(this));
Here's where I run into trouble. On the tab selected listener, I do the following, which I'm sure is going wrong (Layout is an empty linear layout):
GoogleMapFragment mapFragment = new GoogleMapFragment();
fragmentTransaction = supportFragmentManager.beginTransaction();
fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(layout.getId(), mapFragment);
fragmentTransaction.commit();
That map fragment looks like:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.map_view, null);
}
When it runs, I get various errors depending on how I tweak this, such as
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f040058, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
Like I said, I'm sure this is wrong, it seems like I'm trying to inflate a fragment twice, or perhaps running into issues by using the same fragment in two spots in the app.
At this point I'm not sure how to fix it. Any advice would be greatly appreciated.