问题
I'm trying to integrate the ActionBarSherlock with Google Maps API v2 fragments.
I have a layout with 2 fragments: one for a list layout and another with a SupportMapFragment.
When I click on a list item first go well but when I click on a list item second time, it throws an error: " Duplicate id 0x7f040038, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment"
I tried several solutions and none of them have been able to fix it. Is there something I'm doing wrong? Please help me!!
I modified ActionBarSherlock to include SherlockMapFragment implemented to support the new SupportMap (as shown here: https://gist.github.com/4392030).
This is my code: https://github.com/inigo-jimenez/TestGoogleMaps
回答1:
This is not a problem with ActionBarSherlock, but a broader one when you have SupportMapFragment inside your custom fragment.
You need to use getChildFragmentManager() to add SupportMapFragment and not through xml.
Take a look at my answer here: MapFragment in Fragment, alternatives?
回答2:
Take the id off the Item list fragment in your XML file.
Then put the fragment inside a container layout (LinearLayout). If you need to refer to the fragment go through that layout.
Make sure that you use the onCreateView function instead of the onCreate inside the fragment class.
来源:https://stackoverflow.com/questions/14481950/actionbarsherlock-google-maps-api-v2-duplicate-id