2013-01-21 168 views
0

當我選擇它向上工作的標籤時,但當我回去時,內容變成白色。 logcat的示出了:ActionBar片段上的Sherlock ViewPager

致命異常:主java.lang.IllegalArgumentException異常:(。:ID/list_news_frame_ * COM ),用於片段 FeedPlayerNews *片段{4055c188#4的ID未發現ID 0x7f040070視圖 = 0x7f040070}在 android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903) 在 android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) 在 android.support .v4.app.BackStackRecord.run(BackStackRecord.java:682) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444) 在 android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461) 在 android.support.v4.app。 FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:523) at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:495) at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:476) at com。 .viewpager.TabsAdapter.onTabSelected(TabsAdapter.java:76)在 com.actionbarsherlock.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:526) 在 com.actionbarsherlock.internal.app.ActionBarImpl $ TabImpl.select (ActionBarImpl.java:907) 在 com.actionbarsherlock.internal.widget.ScrollingTabContainerView $ TabClickListener.onClick(ScrollingTabContainerView.java:504) 在android.view.View.performClick(View.java:2506)在 機器人。 view.View $ PerformClick.run(View.java:9112)at android.os.Handler.handleCallback(Handler.java:587)at android.os.Handler.dispatchMessage(Handler.java:92)at android。 os.Looper.loop(Looper.java:130)at android.app.ActivityThread.main(ActivityThread.java:3835)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:507)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:864) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)at dalvik.system.NativeStart.main(本地方法)

我的類:

public class TabsAdapter extends FragmentPagerAdapter implements 
     ActionBar.TabListener, ViewPager.OnPageChangeListener { 
    private final Context mContext; 
    private final ActionBar mActionBar; 
    private final ViewPager mViewPager; 
    private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); 
    ProgressDialog dialog; 

    static final class TabInfo { 
     private final Class<?> clss; 
     private final Bundle args; 

     TabInfo(Class<?> _class, Bundle _args) { 
      clss = _class; 
      args = _args; 
     } 
    } 

    public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { 
     super(activity.getSupportFragmentManager()); 
     mContext = activity; 
     mActionBar = activity.getSupportActionBar(); 
     mViewPager = pager; 
     mViewPager.setAdapter(this); 
     mViewPager.setOnPageChangeListener(this); 
    } 

    public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) { 
     TabInfo info = new TabInfo(clss, args); 
     tab.setTag(info); 
     tab.setTabListener(this); 
     mTabs.add(info); 
     mActionBar.addTab(tab); 
     notifyDataSetChanged(); 
    } 

    public int getCount() { 
     return mTabs.size(); 
    } 

    public SherlockFragment getItem(int position) { 
     TabInfo info = mTabs.get(position); 
     return (SherlockFragment) Fragment.instantiate(mContext, 
       info.clss.getName(), info.args); 
    } 

    public void onPageScrolled(int position, float positionOffset, 
      int positionOffsetPixels) { 
    } 

    public void onPageSelected(int position) { 
     mActionBar.setSelectedNavigationItem(position); 
    } 

    public void onPageScrollStateChanged(int state) { 
    } 

    public void onTabSelected(Tab tab, FragmentTransaction ft) { 
     mViewPager.setCurrentItem(tab.getPosition()); 
     Object tag = tab.getTag(); 
     for (int i = 0; i < mTabs.size(); i++) { 
      if (mTabs.get(i) == tag) { 
       mViewPager.setCurrentItem(i); 
      } 
     } 
    } 

    public void onTabUnselected(Tab tab, FragmentTransaction ft) { 
    } 

    public void onTabReselected(Tab tab, FragmentTransaction ft) { 
    } 

} 

UPDATE:

其持有viewpager方法:

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     ConnectionChangeReceiver cm = new ConnectionChangeReceiver(); 
     cm.onReceive(this, getIntent()); 

     mViewPager = new ViewPager(this); 
     mViewPager.setId(R.id.viewpager); 
     setContentView(mViewPager); 

     RssReaderTask.setRssUrl(this, 
       "http://url?type=rss"); 
     SchedulerManager.getInstance().saveTask(this, "0 9-20 * * 1,2,3,4,5", 
       RssReaderTask.class); 
     SchedulerManager.getInstance().restart(this, RssReaderTask.class); 


     NotifyClass.getInstance().setSlideCreate(true); 

     if (!isOnline()) { 
      showDialog(DIALOG_ERROR_CONNECTION); 
      Log.d("TAG", "TRUE"); 
     } 

     if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { 
      // do nothing 
     } else { 
      this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     } 
     globalvar = new GlobalVariable(); 
     globalvar.set_radio_encours_global(false); 
     globalvar.setOnHold_global(false); 

     mTabsAdapter = new TabsAdapter(this, mViewPager); 

     bar = getSupportActionBar(); 
     bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
     bar.setDisplayShowTitleEnabled(false); 
     bar.setDisplayShowHomeEnabled(false); 

     mTabsAdapter.addTab(bar.newTab().setText("Tab1"), 
       Tab1.class, null); 
     mTabsAdapter.addTab(bar.newTab().setText("Tab2"), Tab2.class, 
       null); 
     mTabsAdapter.addTab(bar.newTab().setText("Tab3 "), 
       Tab3.class, null); 
     mTabsAdapter.addTab(bar.newTab().setText("Tab4"), 
       Tab4.class, null); 

    } 

回答

0

您的類是確定的,它應該是工作,我使用的是相同的,它的作品......我認爲這是在你的活動/片段一個問題,持有viewpager,所以我建議檢查你的onCreate/onCreateView方法。
如果找不到任何內容,請從此方法或類的代碼發佈代碼,如果指定的方法不是錯誤的原因。