Say you show a ImageViewFragment (which is a subclass of a Fragment) for 
each page in your ViewPager.
Your ViewPager uses a FragmentPagerAdapter to handle the in-and-out swiping 
of ImageViewFragments.

Implement these methods for your ImageViewFragment class:
* @Override*
* public void onViewCreated(View view, Bundle savedInstanceState) {*
* super.onViewCreated(view, savedInstanceState);*
* *
* imageShowing = true;*
* assignImage(resDrawableId); // resDrawableId is the resourceId of an 
image. 
*
* }*
*
*
* @Override*
* public void onDestroyView() {*
* // Clean up resources asap. Images could be large.*
* assignImage(0);*
* imageShowing = false;*
* *
* super.onDestroyView();*
* }*
*
*
* private void assignImage(int resourceId) {*
* if (resourceId > 0) {*
* imgView.setImageResource(resourceId);*
* }*
* else {*
* imgView.setImageDrawable(null);*
* }*
* }*

Instead of 'int resourceId', you could have a 'Bitmap image' parameter (and 
change the code accordingly). The main point is to implement *onViewCreated 
*and *onDestroyView *to show and hide/clean-up your images.

The FragmentPagerAdapter is smart enough to keep the currently shown 
ImageViewFragment, the one before it (if any) and the one after it (if any) 
and call 'onDestroyView' on the others appropriately.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to