2

我正在使用actionbarsherlock及其sherlockFragmentActivity。谷歌地圖片段:inflater.inflate崩潰時,在ViewPager中創建並重新創建?

我有3個片段,並在一個Tab + ViewPager佈局。

第三個片段是問題。它是一個顯示我在谷歌地圖上的位置的片段。

從我注意到,viewpager,將創建新的頁面,如果我們滾動頁面超過1頁,那麼它將DESTORY該頁面。

所以它第一次好,我去第2頁,它使用GOOGLEMAPS在第3頁上調用CREATE。

但問題是如果我回到第1頁(DESTORIES第3頁googlemaps)。現在,如果我回到第2頁(嘗試創建第3頁),page3的inflater.inflate將DIE,我會得到一個錯誤,首先是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 
+0

堆棧跟蹤應該幫助。 – Geros 2013-05-14 01:45:51

回答