hackware1993 / MagicIndicator

A powerful, customizable and extensible ViewPager indicator framework. As the best alternative of ViewPagerIndicator, TabLayout and PagerSlidingTabStrip —— 强大、可定制、易扩展的 ViewPager 指示器框架。是ViewPagerIndicator、TabLayout、PagerSlidingTabStrip的最佳替代品。支持角标,更支持在非ViewPager场景下使用(使用hide()、show()切换Fragment或使用setVisibility切换FrameLayout里的View等),http://www.jianshu.com/p/f3022211821c
9.74k stars 1.55k forks source link

在onLayout里触发onPageSelected所导致的Bug #159

Open ZZombiee opened 5 years ago

ZZombiee commented 5 years ago

我的列表里菜单可以弹出键盘 只要弹出键盘,就会触发CommonNavigator的onLayout,然后间接触发onPageSelected,而我又在这个回调里设置了不同Fragment的刷新操作 现象就变成了弹出键盘就触发刷新,产生了较为严重的Bug 我觉得至少需要加一个监听,onPageSelectChanged

ZZombiee commented 5 years ago
public class YNavigator extends CommonNavigator {
    private int mIndex = -1;

    public YNavigator(Context context) {
        super(context);
    }

    @Override
    public void onPageSelected(int position) {
        if (mIndex != position)
            onPageSelectChanged(mIndex, position);
        super.onPageSelected(position);
        mIndex = position;
    }

    public void onPageSelectChanged(int position, int goal) {
        if (getAdapter() != null) {
            if (getPagerIndicator() != null && getPagerIndicator() instanceof YLinePageIndicator) {
                ((YLinePageIndicator) getPagerIndicator()).onPageSelectChanged(position, goal);
            }
        }

    }
}
  @Override
            public IPagerIndicator getIndicator(Context context) {
                YLinePageIndicator indicator = new YLinePageIndicator(context) {
                    @Override
                    public void onPageSelectChanged(int position, int goal) {
                        L.d("YLinePageIndicator", "onPageSelectChanged:" + position + "," + goal);
                        ((TabFragment) tabAdapter.getItem(goal)).getDetail();
                    }

                    @Override
                    public void onPageSelected(int position) {
                        L.d("YLinePageIndicator", "onPageSelected:" + position + "");
                    }
                };
                indicator.setLineHeight(AppUtils.auto_height_px(getResources().getDimension(R
                        .dimen.p1)));
                indicator.setColors(context.getResources().getColor(R.color.btn_orange));
                return indicator;
            }

这样就好了

mybirthfather commented 5 years ago

我也有这个问题但是我是要在onSelected 的时候 reset 我的某一部分数据 但是现在 弹出键盘就给我初始化了 卧槽 我蒙蔽了

spuermax commented 4 years ago

https://blog.csdn.net/qq_37492806/article/details/103736312

可以参考一下 。