调用部分:
mNewsViewPager = (ViewPager)mTopView.findViewById(R.id.adViewPager);
if (!mItems.isEmpty()) {
mElements.clear();
for(int i=0;i<3;i++)
{
view=mInflater.inflate(R.layout.vp_content,null);
textView=(TextView)view.findViewById(R.id.top_title);
textView.setText("something");
mElements.add(view);
}
mPageAdaper.notifyDataSetChanged();
}
else
{
for(int i=0;i<3;i++)
{
view=mInflater.inflate(R.layout.vp_content,null);
mElements.add(view);
}
}
mNewsViewPager.setAdapter(mPageAdaper);
mNewsViewPager.setCurrentItem(0);
OnPageChangeListener pageChangeListener =new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
@Override
public void onPageScrolled(int position,
float positionOffset, int positionOffsetPixels) {
}
};
mNewsViewPager.setOnPageChangeListener(pageChangeListener);
mItems填充数据后显示的仍然是原界面文字没有改变;
PagerAdapter源代码,网上的更改getItemCount()函数我试过了没用
public class mPagerAdapter extends PagerAdapter {
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public int getCount() {
return mElements.size();
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public void startUpdate(View arg0) {
}
@Override
public void finishUpdate(View arg0) {
}
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView(mElements.get(position));
}
@Override
public Object instantiateItem(View container, int position) {
((ViewPager) container).addView(mElements.get(position));
return mElements.get(position);
}
};