下面是我的代码,请各位指点下。
当界面向回滚动时报如下错误:
public class HistoryViewpagerAdapter extends PagerAdapter {
private HashMap<Integer,Boolean> loadFlag;
private ArrayList<String> titles;
/**
* 点检时间的原始集合
*/
private ArrayList<String> list;
private HashMap<Integer, View> views;
private int viewcount;
private Context context;
public HistoryViewpagerAdapter(Context c, HistoryActivity ha, ArrayList<String> titles,
HashMap<Integer, View> views, int count, ArrayList<String> list)
{
this.titles = titles;
this.views = views;
this.viewcount = count;
this.list = list;
this.context = c;
InitFlag(titles);
}
private void InitFlag(ArrayList<String> titles)
{
loadFlag = new HashMap<Integer, Boolean>();
for(int j = 0; j < titles.size(); j++)
{
loadFlag.put(j, false);
}
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.titles.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return arg0 == arg1;
}
@Override
public void destroyItem(View container, int position, Object object) {
// TODO Auto-generated method stub
int index = position % viewcount;
((ViewPager)container).removeView(views.get(index));
}
@Override
public Object instantiateItem(View container, int position) {
// TODO Auto-generated method stub
int index = position % viewcount;
((ViewPager)container).addView(views.get(index));
return views.get(index);
}
@Override
public CharSequence getPageTitle(int position) {
// TODO Auto-generated method stub
return titles.get(position);
}
@Override
public void setPrimaryItem(View container, int position, Object object) {
// TODO Auto-generated method stub
if(!loadFlag.get(position))
{
ReSetData(position);
}
}
public RelativeLayout getItem(int position){
int index = position % viewcount;
return (RelativeLayout)views.get(index);
}
/**
* 重新载入数据
* @param position
*/
private void ReSetData(int position){
int index = position % viewcount;
RelativeLayout layout = (RelativeLayout)views.get(index);
String layouttag = (String)layout.getTag(R.id.viewpager_tag_first);
ListView listView = (ListView)layout.findViewWithTag(layouttag);
int tag = (int)listView.getTag(R.id.viewpager_tag_second);
if(tag != position)
{
loadFlag.put(tag, false);
HisSpkHelper hisSpkHelper = new HisSpkHelper(context);
String date = list.get(position);
HistoryListviewAdapter listviewAdapter = (HistoryListviewAdapter)listView.getAdapter();
listviewAdapter.setDatas(hisSpkHelper.Select_(date));
listView.setTag(R.id.viewpager_tag_second, position);
listviewAdapter.notifyDataSetChanged();//数据更新完成,刷新界面
hisSpkHelper.close();
loadFlag.put(position, true);
}
}
}
当界面向回滚动时报如下错误:
