setArguments(bundle) is undefined



使用FragmentPagerAdapter,我正试图返回一个片段。然而,我最终出现错误setArgument(bundle)未定义。但我不想定义它,看看其他样本代码

这是代码

    public static SimpleMapActivity newInstance(int position,String title) {
    SimpleMapActivity fragment = new SimpleMapActivity();
    Bundle bundle = new Bundle();
    bundle.putInt("position", position);
    bundle.putString("title", title);
    fragment.setArguments(bundle);
    return fragment;
}

我创建的PageAdapter是;

        @Override
    public Fragment getItem(int position) {
            Fragment fragmentByTag = getSupportFragmentManager().findFragmentByTag(makeFragmentName(R.id.pager, position));
            System.out.println("*********** fragmentByTag = " + fragmentByTag);
            return SimpleMapActivity.newInstance(position, "Fragment with menu");
        }

我可以放更多的代码,但我认为这已经足够解决它了,如果你想看更多,请毫不犹豫地问。提前感谢,Alejandro

SimpleMapActivity没有扩展Fragment,这就是没有定义setArguments方法的原因。

SimpleMapActivity是否执行了片段?它看起来像活动。

最新更新