java如何添加下一组片段而不干扰FragmentPagerAdapter中的当前片段?
下面是第一次添加片段的代码`
`if(mcursor==null){ items=(ArrayList)cnews。getItems(); mcursor=cnews。getNextPageToken()
for (int i = 0; i < items.size(); i++) {
Fragment cm = ContentFragment.newInstance(i, items.get(i).getTitle(),
items.get(i).getImageuri(), items.get(i).getDate(), items.get(i).getPublsher(), items.get(i).getDescription());
frags.add(cm);
}
viewPager.setAdapter(new ContentfragmentAdapter(getSupportFragmentManager(), frags));
}else{
items = (ArrayList<News>) cnews.getItems();
mcursor = cnews.getNextPageToken();
for (int i = 0; i < items.size(); i++) {
Fragment cm = ContentFragment.newInstance(i, items.get(i).getTitle(),
items.get(i).getImageuri(), items.get(i).getDate(), items.get(i).getPublsher(), items.get(i).getDescription());
frags.add(cm);
}
在其他情况下,我想在服务器调用后添加更多片段。如何在不删除旧片段的情况下更新适配器
请帮帮我,我是安卓开发的新手。 非常感谢
# 1 楼答案
这里最重要的一点是你必须打电话
使基础数据结构相应更新 包括触发ViewPager的重画。 也不要忘记
getCount()
还必须返回预期的元素数(即这里没有硬编码值)