在 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();
}