问题!
我正在使用带有图标的TabLayout 那是我的Adapater
public class ViewPagerIconsAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
public ViewPagerIconsAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment) {
mFragmentList.add(fragment);
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public CharSequence getPageTitle(int position) {
return "";
}
}
这就是我使用我的适配器在ViewPager中添加片段并在我的TabLayout中显示图标
的方法tabLayout = (TabLayout)findViewById(R.id.tabLayout);
viewPager = (ViewPager)findViewById(R.id.viewpager);
viewPager.setOffscreenPageLimit(3);
setupViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
setupTabIcons();
setupViewPager方法
adapter = new ViewPagerIconsAdapter(getSupportFragmentManager());
adapter.addFragment(new Fragment1());
adapter.addFragment(new Fragment2());
adapter.addFragment(new Fragment3());
viewPager.setOffscreenPageLimit(3);
viewPager.setAdapter(adapter);
setupTabIcons方法
tabLayout.getTabAt(0).setIcon(tabIcons[0]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
tabLayout.getTabAt(2).setIcon(tabIcons[2]);
问题是当我使用notifyDataSetChanged来刷新我的viewPager时,所有图标都消失了。
adapter.notifyDataSetChanged();
有人有想法吗?
答案 0 :(得分:0)
如果您的图标已修复 试试这个: tabLayout.setupWithViewPager(viewPager,FALSE);