Skip to content

项目中使用AdapterViewPager类会出现跳转bug #219

@yogkin

Description

@yogkin

Bug Description:

Related Code:

  @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment f = (Fragment) super.instantiateItem(container, position);
        View view = f.getView();
        if (view != null)
            container.addView(view);
        return f;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = mList.get(position).getView();
        if (view != null)
            container.removeView(view);
    }

分析原因

当切换viewpager会执行上面的2个方法,如果执行了destroyItem() 则在页面跳转时候(比如跳转到其他Activity)会发生crash
原因应该是 viewpager会在跳转前执行removeViews()方法,导致NullPointerException 不知道我分析得对不对
最后感谢作者提供这么好的框架给我们学习

Bug Log:

image

Others:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions