【问题标题】:Return different Fragment Types返回不同的片段类型
【发布时间】:2013-06-07 12:58:39
【问题描述】:

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

@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?

【问题讨论】:

标签: android actionbarsherlock fragment android-listfragment


【解决方案1】:

这样改

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

【讨论】:

  • 您好,我有一个类似的问题,实际上我已经将我的片段放在了浏览器中,但想根据特定条件返回不同的片段。 stackoverflow.com/q/18030296/1503130
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多