2

我正在使用 actionbarsherlock 及其 sherlockFragmentActivity。

我有 3 个片段和 Tab + ViewPager 布局。

第三个片段是问题所在。这是一个片段,在谷歌地图上显示我的位置。

据我所知,viewpager 将创建新页面,如果我们从一个页面滚动超过 1 页,那么它将破坏该页面。

所以第一次一切都很好,我转到第 2 页,它使用 GOOGLMAPS 在第 3 页调用 CREATE。

但是,问题是如果我回到第 1 页(DESTORIES 第 3 页 googlemaps)。现在,如果我回到第 2 页(尝试创建第 3 页),第 3 页的 inflater.inflate 会死掉,我会得到一个错误,首先是 Choreographer 类。

所以我的问题是,为什么 inflater.inflate 失败了,用这样的片段编程选项卡 viewpager 的正确方法是什么????

此处的代码(在创建主要活动时):

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main_activity);
        mTabHost = (TabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup();

        mViewPager = (ViewPager)findViewById(R.id.pager);

        mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);

        mTabsAdapter.addTab(mTabHost.newTabSpec("driverInfo").setIndicator("Driver Info"),
                DriverInfo.class, null);
        mTabsAdapter.addTab(mTabHost.newTabSpec("alarmSystem").setIndicator("Alarm System"),
                AlarmSetting.class, null);
        mTabsAdapter.addTab(mTabHost.newTabSpec("vehicleLocation").setIndicator("Location"),
                VehicleLocation.class, null);


        if (savedInstanceState != null) {
            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("tab", mTabHost.getCurrentTabTag());
    }

代码:位置片段:

public class VehicleLocation extends Fragment implements ServerRequestInterface {

    private GoogleMap mMap; 
    private ProgressDialog mProgressDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        try
        {
            super.onCreate(savedInstanceState);
            setupProgressDialog();
        }
        catch (Exception ex)
        {
            System.out.println(ex.toString());
        }


}

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//WHere it keeps die-ing     ----------------------------------    
    View view = inflater.inflate(R.layout.vehicle_location, container, false);
            setUpMapIfNeeded();
            return view;
        }

错误日志:

05-13 20:48:31.532: E/AndroidRuntime(13219): FATAL EXCEPTION: main
05-13 20:48:31.532: E/AndroidRuntime(13219): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at com.covixon.main.VehicleLocation.onCreateView(VehicleLocation.java:37)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.view.ViewPager.populate(ViewPager.java:880)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.view.ViewPager$3.run(ViewPager.java:238)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer.doFrame(Choreographer.java:531)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.os.Handler.handleCallback(Handler.java:725)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.os.Looper.loop(Looper.java:137)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.app.ActivityThread.main(ActivityThread.java:5237)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at java.lang.reflect.Method.invokeNative(Native Method)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at java.lang.reflect.Method.invoke(Method.java:511)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at dalvik.system.NativeStart.main(Native Method)
05-13 20:48:31.532: E/AndroidRuntime(13219): Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f040066, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-13 20:48:31.532: E/AndroidRuntime(13219):    ... 26 more
4

1 回答 1

2

在更多地盯着堆栈跟踪之后,我注意到了这条线

 Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f040066, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment

这导致我像谷歌一样,这解决了我的问题:

ID、标签 null 或父 ID 与 com.google.android.gms.maps.MapFragment 的另一个片段重复

于 2013-05-14T14:20:59.420 回答