如何从视图寻呼机中永久删除页面。我想在用户按下该屏幕上的按钮时删除页面。我在这方面苦苦挣扎。我阅读了pageradapter的文档并找到了destroyitem,但它对我没什么帮助。我可以在viewpager中添加图像,但删除仍然给我一个艰难的时间。请帮忙。
以下是获取图像的活动的代码,我想根据用户请求删除图像。
public class ImageDisplayActivity extends Activity {
private List<String> filePaths;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display1);
// Get Image Paths for the PagerAdapter
filePaths = getIntent().getExtras().getStringArrayList("filePaths");
int currPosition = getIntent().getExtras().getInt("position");
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setCurrentItem(currPosition);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
}
private class ImagePagerAdapter extends PagerAdapter {
@Override
public int getCount() {
return filePaths.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = ImageDisplayActivity.this;
ImageView imageView = new ImageView(context);
int padding = 16;
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
// Get Image
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = 4;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(filePaths.get(position), bmOptions);
// Display Image
imageView.setImageBitmap(bitmap);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object imageView) {
((ViewPager) container).removeView((ImageView) imageView);
}
}
}
答案 0 :(得分:0)
正如@Kuffs所说,从filePaths中删除项目,然后通知适配器基础数据已经改变:
filePaths.remove(...); // Remove whatever you want
adapter.notifyDatasetChanged(); // Tell the adapter that it's time to update views
答案 1 :(得分:0)
我发布了答案,因为我无法发表评论。
您可以尝试从适配器中删除它。将其添加到您的destroyItem:
service.uploadRecord(file,size,new Callback<Map<String, Object>>()
{
@Override
public void success(Map<String, Object> stringObjectMap, Response response) {
Message msg=new Message();
msg.obj=stringObjectMap;
msg.what=MESSAGE_UPLOADING_STOP;
handler.sendMessage(msg);
}
@Override
public void failure(RetrofitError error) {
handler.sendMessage(createErrorMsg(error.getMessage()));
Log.e(RECORDER_TAG,"error--"+error.getMessage());
}
});
而且,你必须使ImagePagerAdapter成为一个全局变量。 希望这有帮助!