0

我有以下方法可以返回不同的片段:

@Override
    public SherlockFragment getItem(int position) {
        SherlockFragment fragment = null;
        if (position == 0) {
            fragment = new MyFragment();
            Bundle args = new Bundle();
            fragment.setArguments(args);
        } else if (position == 1) {
            fragment = new MyFragment2();
            Bundle args = new Bundle();
            fragment.setArguments(args);
        } else if (position == 2) {
            fragment = new MyListFragment();
            Bundle args = new Bundle();
            fragment.setArguments(args);
        }
        return fragment;
    }

如何返回 2 次 SherlockFragment 和 1 次 SherlockListFragment?

4

1 回答 1

2

改成这样

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        if (position == 0) {
            fragment = new MyFragment();
            Bundle args = new Bundle();
            fragment.setArguments(args);
        } else if (position == 1) {
            fragment = new MyFragment2();
            Bundle args = new Bundle();
            fragment.setArguments(args);
        } else if (position == 2) {
            fragment = new MyListFragment();
            Bundle args = new Bundle();
            fragment.setArguments(args);
        }
        return fragment;
    }
于 2013-06-07T13:00:36.053 回答