private void initView(){
dateAfterSplit=mScreen.split(",");
tips = new ImageView[dateAfterSplit.length];
for(int i=0; i<tips.length; i++){
ImageView imageView = new ImageView(this);
imageView.setLayoutParams(new LayoutParams(10,10));
tips[i] = imageView;
if(i == 0){
tips[i].setBackgroundResource(R.drawable.page_indicator_focused);
}else {
tips[i].setBackgroundResource(R.drawable.page_indicator_unfocused);
}
mGroup.addView(imageView);
}
mImageViews=new ImageView[dateAfterSplit.length];
for(int i=0; i<mImageViews.length; i++){
ImageView imageView = new ImageView(this);
mImageViews[i] = imageView;
mImageLoader.displayImage(imageView, dateAfterSplit[i],
R.drawable.app_icon, mIsLoaderAlbumFromCache);
}
mViewPager.setAdapter(new MyAdapter());
mViewPager.setOnPageChangeListener(this);
mViewPager.setCurrentItem(mPictureId);}
Left and right infinite loop
public class MyAdapter extends PagerAdapter{
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((ImageView) mImageViews[position % mImageViews.length]);
Log.i("APP", "destroyItem"+position);
}
@Override
public Object instantiateItem(View container, int position) {
try{
if(mImageViews[position % mImageViews.length].getParent()==null){
((ViewPager)container).addView(mImageViews[position % mImageViews.length]);
}
else {
((ViewGroup)mImageViews[position % mImageViews.length].getParent()).removeView(mImageViews[position % mImageViews.length]);
((ViewPager) container).addView(mImageViews[position % mImageViews.length] , 0);
}
} catch (Exception e) {
e.printStackTrace();
}
Log.i("APP", "instantiateItem"+position);
return mImageViews[position % mImageViews.length];
}
}
答案 0 :(得分:0)
尝试将此添加到PagerAdapter,这可以解决您的问题
public int getItemPosition(Object object){return POSITION_NONE; }