嗨,我想在滑动时更新 viewpager 片段的视图(类似于 setOffscreenPageLimit = 0 不起作用,因为最小偏移量为 1)但我不知道如何。我尝试使用界面,但在我尝试设置的可见性部分视图中出现空指针异常:
pager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
((OnRefreshListener) adapter.getItem(position)).onRefresh();
}
@Override
public void onPageScrollStateChanged(int arg0) {}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {}
});
实现接口:
@Override
public void onRefresh() {
if(AddLesson.addNext) {
addDetails.setVisibility(View.GONE);
addLesson.setVisibility(View.GONE);
addWithData.setVisibility(View.VISIBLE);
addWithoutData.setVisibility(View.VISIBLE);
}
}
FragmentStatePagerAdapter:
class TabsAdapter extends FragmentStatePagerAdapter {
public TabsAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
AddLessonDetails addDetails = AddLessonDetails.newInstance(CONTENT[position]);
return addDetails;
}
@Override
public CharSequence getPageTitle(int position) {
return CONTENT[position % CONTENT.length];
}
@Override
public int getCount() {
return CONTENT.length;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
我能做些什么来解决这个问题?