FragmentPagerAdapter 按项目向导
公共类 SectionsPagerAdapter 扩展 FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = new ChapterPageFragment();
if (currentPart != null) {
Bundle args = new Bundle();
Chapter chapter = currentPart.getChapters().get(position);
if (chapter.getVerses() == null) {
chapter.setVerses(currentDao.readVerses(currentPart, chapter));
}
args.putParcelable(Chapter.KEY, currentPart.getChapters().get(position));
fragment.setArguments(args);
}
return fragment;
}
@Override
public int getCount() {
if (currentPart == null) {
return 0; // Before Initialzing
}
return currentPart.getChapterCount();
}
@Override
public CharSequence getPageTitle(int position) {
return getString(R.string.chapter_format, position+1);
}
}
何时更改数据
actionListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
currentPart = currentBook.getParts().get(position);
viewPager.getAdapter().notifyDataSetChanged();
slideMenu.showContent();
}
});
查看页面计数已更改,但页面(片段)内容未更改。
例如,
选择 A 部分,3 页:“A1”、“A2”、“A3”
然后选择B部分,5页:“A1”、“A2”、“A3”、“B4”、“B5” (不是“B1”、“B2”、“B3”、“B4”、“B5”)
如何将页面内容 A 更改为 B?