Android 17 でアプリを作成しており、Google マップ v2 を含めようとしています。
私の現在の設定では、2 つのタブを持つ ActionBar があり、1 つは旅行情報を指し、もう 1 つは Google マップを指しています。
Google マップをメイン アクティビティに表示することはできますが、マップをフラグメントに表示することはできません。
これが私のマップクラスのコードです:
// Will hold the information for the "Maps" tab
public class Maps extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setCustomView(R.layout.rowlayout);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Venue Map
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layoutView = (RelativeLayout)inflater.inflate(R.layout.action_bar_tab, null);
TextView tabText = (TextView) layoutView.findViewById(R.id.tabText);
ImageView tabImage = (ImageView) layoutView.findViewById(R.id.tabImage);
String venueMapTab = "Travel Information";
Tab tab = actionBar.newTab();
TabListener<VenueMap> dayOne = new TabListener<VenueMap>(this,
venueMapTab, VenueMap.class);
tab.setTabListener(dayOne);
tabText.setText("Venue Map");
tab.setCustomView(layoutView);
actionBar.addTab(tab);
// Google Maps
RelativeLayout layoutViewMaps = (RelativeLayout)inflater.inflate(R.layout.action_bar_tab, null);
tabText = (TextView) layoutViewMaps.findViewById(R.id.tabText);
tabImage = (ImageView) layoutViewMaps.findViewById(R.id.tabImage);
String googleMapsTab = "Google Maps";
tab = actionBar.newTab();
TabListener<GoogleMaps> dayTwo = new TabListener<GoogleMaps>(this,
googleMapsTab, GoogleMaps.class);
tab.setTabListener(dayTwo);
tabText.setText("Google Maps");
tab.setCustomView(layoutViewMaps);
actionBar.addTab(tab);
}
これが私のGoogleマップのフラグメントです
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getActivity().setContentView(R.layout.google_maps);
}
そして google_maps.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
そして私のログ猫のエラー:
01-28 13:44:09.830: E/AndroidRuntime(22253): FATAL EXCEPTION: main
01-28 13:44:09.830: E/AndroidRuntime(22253): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zshare.blog/com.zshare.blog.Maps}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.os.Looper.loop(Looper.java:137)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-28 13:44:09.830: E/AndroidRuntime(22253): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 13:44:09.830: E/AndroidRuntime(22253): at java.lang.reflect.Method.invoke(Method.java:511)
01-28 13:44:09.830: E/AndroidRuntime(22253): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-28 13:44:09.830: E/AndroidRuntime(22253): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-28 13:44:09.830: E/AndroidRuntime(22253): at dalvik.system.NativeStart.main(Native Method)
01-28 13:44:09.830: E/AndroidRuntime(22253): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-28 13:44:09.830: E/AndroidRuntime(22253): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.Activity.setContentView(Activity.java:1881)
01-28 13:44:09.830: E/AndroidRuntime(22253): at com.zshare.blog..VenueMap.onActivityCreated(VenueMap.java:32)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.Fragment.performActivityCreated(Fragment.java:1703)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.Activity.onCreateView(Activity.java:4736)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-28 13:44:09.830: E/AndroidRuntime(22253): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.Activity.setContentView(Activity.java:1881)
01-28 13:44:09.830: E/AndroidRuntime(22253): at com.zshare.blog.VenueMap.onActivityCreated(VenueMap.java:32)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.Fragment.performActivityCreated(Fragment.java:1703)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.BackStackRecord.run(BackStackRecord.java:682)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.Activity.performStart(Activity.java:5113)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
01-28 13:44:09.830: E/AndroidRuntime(22253): ... 11 more
01-28 13:44:09.830: E/AndroidRuntime(22253): Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f05003b, tag null, or parent id 0x1020002 with another fragment for com.google.android.gms.maps.MapFragment
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.app.Activity.onCreateView(Activity.java:4722)
01-28 13:44:09.830: E/AndroidRuntime(22253): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
01-28 13:44:09.830: E/AndroidRuntime(22253): ... 35 more
アクティビティでマップを表示すると機能しますが、フラグメントでエラーが発生します。この問題を解決する助けをいただければ幸いです:)