I have an Android FragmentPagerAdapter that uses BitmapFragment (below), and it works great. Now I'm trying to switch out the Images on the fly. I've tried changing the ImageView but nothing changes. And I've tried using a FragmentTransaction.replace to swap it out, but I get an Invalid Argument exception. I know getImageViewAtPage() works and "bitmap" is a valid Bitmap.
Thanks!
private class BitmapFragment extends Fragment {
private int mPosition = 0;
private ImageView mImageView;
private BitmapFragment(int num){
super();
mPosition = num;
}
public ImageView getImageView(){
return mImageView;
}
/**
* The Fragment's UI is just a Bitmap
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_bitmap, container, false);
try{
mImageView = (ImageView) v.findViewById(R.id.bitmap);
mImageView.setImageBitmap(bitmap);
}
catch(Exception e){
e.printStackTrace();
}
return v;
}
}
private void changeImage() {
/*
BitmapFragment bf = new BitmapFragment(mCurrentPageIndex);
FragmentTransaction ft = mReaderViewHandler.getSupportFra开发者_运维技巧gmentManager().beginTransaction();
ft.replace(R.layout.fragment_bitmap, bf);
ft.commit();
*/
ImageView v = getImageViewAtPage(mCurrentPageIndex);
try {
v.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
v.invalidate();
}
Please try to do mImageView.setImageBitmap()
inside your changeImage()
method instead of using v = getImageViewAtPage
and doing v.setImageBitmap()
.
精彩评论