我有ViewPager,当我打开片段时,我更新了我的bd。但是前一个和下一个Fragment也会更新。 我没有更多的代码:
PagerAdapter pagerNewsAdapter = new PagerNewsAdapter(super.getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager) super.findViewById(R.id.viewpager);
pager.setAdapter(pagerNewsAdapter);
pager.setCurrentItem(getIntent().getExtras().getInt(ITEM_POSITION));
如何防止更新碎片n-1和n + 1?
片段代码:
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new, container,
false);
TextView txtTitle = (TextView) view.findViewById(R.id.titleNew);
txtTitle.setTypeface(custom_font_bold);
txtTitle.setText(ac.getTitre());
TextView resume = (TextView) view.findViewById(R.id.res);
resume.setTypeface(custom_font_bold);
resume.setText(Html.fromHtml(ac.getResume()));
resume.setTextColor(getResources().getColor(R.color.grey_500_transparent));
BD_ACTUALITE.updateViewAct(ac);
return view;
}
我的ViewPager:
ArrayList<Fragment> fragments = new ArrayList<>();
for(Act act : arListNews) {
FragmentNew frg = new FragmentNew(act);
fragments.add(frg);
}
PagerAdapter pagerNewsAdapter = new PagerNewsAdapter(super.getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager) super.findViewById(R.id.viewpager);
pager.setAdapter(pagerNewsAdapter);
pager.setCurrentItem(getIntent().getExtras().getInt(ITEM_POSITION));
谢谢所有答案。
答案 0 :(得分:0)
没关系, 我实现了ViewPager.OnPageChangeListener和Override onPageSelected()