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;
    }

SherlockFragment を 2 回、SherlockListFragment を 1 回返すにはどうすればよいですか?

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 に答える