如何在FragmentPagerAdapter中实现FragmentActivity?

时间:2012-11-10 08:15:21

标签: android listview android-activity listactivity

我有一个我的类的部分,用于处理为FragmentPagerAdapter加载的片段。现在它加载片段就好了,但现在我想实现一个FragmentActivity,我有一个问题,想知道如何创建它,因为我不能使用“newinstance”,因为它的Activity类型,在它之上,我不知道如何称FragmentActivity与通过“newinstance”方法加载Fragment不同。我的第二个标签是我想要扩展到FragmentActivity的标签。

public class SectionsPagerAdapter extends FragmentPagerAdapter {
    private Context _context;
    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
        _context= getApplicationContext();
    }

    @Override
    public Fragment getItem(int i) {

        Fragment f = new Fragment();

        switch(i){
        case 0:
            f=News.newInstance(_context);
            break;  
        case 1:
            f=Info.newInstance(_context);
            break;
        case 2:
            f=Files.newInstance(_context);
            break;
        case 3:
            f=Donate.newInstance(_context);
            break;
        }
        /*

        Fragment fragment = new DummySectionFragment();
        Bundle args = new Bundle();
        args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
        fragment.setArguments(args);

       */
        return f;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
        case 0: return getString(R.string.title_section1).toUpperCase();
        case 1: return getString(R.string.title_section2).toUpperCase();
        case 2: return getString(R.string.title_section3).toUpperCase();
        case 3: return getString(R.string.title_section4).toUpperCase();
        }
        return null;
    }
}

我的猜测是我不能使用getitem方法只能切换片段而且我必须使用类似的东西:

FragmentTransaction ft = fm.beginTransaction();
            ft.add(R.id.fragment_content, new BasicFragment());
            ft.commit();

有人可以帮助我指出正确的方向吗?

1 个答案:

答案 0 :(得分:0)

  

有人可以帮助我指出正确的方向吗?

不支持此功能。对FragmentPagerAdapter来说肯定是不可能的,它只适用于片段。

相关问题