0
votes

when I select the tabs upward it works, but when I go back the content becomes white. LogCat shows:

FATAL EXCEPTION: main java.lang.IllegalArgumentException: No view found for id 0x7f040070 (com..:id/list_news_frame_*) for fragment FeedPlayerNews*Fragment{4055c188 #4 id=0x7f040070} at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461) at 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) at com.actionbarsherlock.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:526) at com.actionbarsherlock.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:907) at com.actionbarsherlock.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:504) at android.view.View.performClick(View.java:2506) at android.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(Native Method)

My class:

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:

the method which holds the 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);

    }
1

1 Answers

0
votes

Your class is ok, it should be working, I am using the same and it works... I think there is a problem in your activity/fragment which holds the viewpager, so I suggest tocheck your onCreate/onCreateView method.
if you can't find anything, post the code from this method or the code of the class if the named method is not the reason for the error.