我该如何notifyDataSetChanged
使用FragmentPagerAdapter
?
在onResume
:
我用过mMyFragmentPagerAdapter.notifyDataSetChanged();
但没用
但是 mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
工作
public class Activity extends FragmentActivity{
static ViewPager mViewPager;
private MyFragmentPagerAdapter mMyFragmentPagerAdapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mViewPager = (ViewPager) findViewById(R.id.pager);
mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mMyFragmentPagerAdapter);
}
private static class MyFragmentPagerAdapter extends FragmentPagerAdapter {
...
}
@Override
protected void onResume() {
super.onResume();
//WORKS
mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mMyFragmentPagerAdapter);
//DOESN'T WORK
mMyFragmentPagerAdapter.notifyDataSetChanged();
mViewPager.setAdapter(mMyFragmentPagerAdapter);
}
}
填充:
public void startView() {
this.questions.clear(); // this.questions is a LinkedList
this.questions.add(q);
}