从服务获取数据时,我将所有数据重新加载到阵列列表中并传递给适配器,但是适配器显示我的旧数据。当我在适配器中打印阵列列表时,我在适配器中传递新数据。向我显示旧数据。当我加载新数据时数据我也清除了所有数据库。
我在视图寻呼机中加载数据,所以我创建了newInstance.so,下面的代码从服务获取数据并将其存储在arraylist中并传递给适配器
adapter = new PagerAdapter(activity.getSupportFragmentManager(),"TotalCount",firstCountArrayList,secondAcoountArrayList,totalCountArrayList);
pager.setPageMargin(-400);
pager.setAdapter(adapter);
adapter.notifyDataSetChanged();
pager.setOffscreenPageLimit(firstCountArrayList.size());
tabs.setViewPager(pager,selected);
在PagerAdapter中,我得到了旧的arraylist数据
public class PagerAdapter extends FragmentPagerAdapter {
String TotalCount = "";
ArrayList<String> firstCountArrayList,secondAcoountArrayList,totalCountArrayList;
public PagerAdapter(FragmentManager fm, String TotalCount, ArrayList<String> firstCountArrayList, ArrayList<String> secondAcoountArrayList, ArrayList<String> totalCountArrayList
) {
super(fm);
//super(fm);
this.TotalCount=TotalCount;
this.firstCountArrayList=firstCountArrayList;
this.secondAcoountArrayList=secondAcoountArrayList;
this.totalCountArrayList=totalCountArrayList;
}
@Override
public CharSequence getPageTitle(int position) {
return firstCountArrayList.get(position);
}
@Override
public int getCount() {
return firstCountArrayList.size();
}
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public Fragment getItem(int position) {
Log.e(TAG," PagerAdapter firstCountArrayList==>"+firstCountArrayList.toString());
return NewPageInstance.newInstance(position,firstCountArrayList,secondAcoountArrayList,totalCountArrayList);
所有数据传递到NewPageInstance并像之后在TextView上显示
public static NewPageInstance newInstance(int position, String totalCount, ArrayList<String> firstCountArrayList, ArrayList<String> secondAcoountArrayList, ArrayList<String> totalCountArrayList) {
totalCount=totalCount;
firstCountArrayList=firstCountArrayList;
secondAcoountArrayList=secondAcoountArrayList;
totalCountArrayList=totalCountArrayList;
}
所有数据均显示textview
这仅在第一次工作。不刷新视图寻呼机数据。
答案 0 :(得分:0)
在视图页面适配器中添加以下代码:-
public int getItemPosition(Object object) {
return POSITION_NONE;
}
或视图寻呼机已更改的侦听器通知您的视图寻呼机适配器:-
mPagerAdapter.notifyDataSetChanged();