0
在ViewPager中,当用户单击删除按钮时,我试图删除当前页面并移到下一页。 当我尝试下面的代码时,它移动到下一页,但删除最后一页。请帮助我。Android ViewPager删除当前页面并移动到下一个
@Override
public Object instantiateItem(ViewGroup container, final int IdxVal)
{
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
Glide.with(context)
.load(imageListAryVar.get(IdxVal))
.fitCenter()
.into(imageView);
linearLayout.addView(imageView);
container.addView(linearLayout);
return linearLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object)
{
container.removeView((LinearLayout) object);
}
void delCurrentPageFnc()
{
int delIdxVar = viewPager.getCurrentItem();
if(imageListAryVar.size() > 1)
{
if (delIdxVar == imageListAryVar.size() - 1)
viewPager.setCurrentItem(delIdxVar - 1);
else
viewPager.setCurrentItem(delIdxVar + 1);
imageListAryVar.remove(delIdxVar);
notifyDataSetChanged();
}
else finish();
}
你可以尝试,如果你删除你的'如果(delIdxVar == imageListAryVar.size() - 1) viewPager.setCurrentItem(delIdxVar - 1); else viewPager.setCurrentItem(delIdxVar + 1);'? –
如果我删除它,页面将不会自动移动到下一页 –
notifyDataSetChanged();将不会调用instantiateItem(); –