Android lazy images ViewFlipper
I have a problem.
I have fragment with ViewFlipper and some string data array (images urls).
How do I do a lazy load of these images and show progressbar until the image is loaded(And caching them if possible)? Can I use a different view(not ViewFlipper)?
And second question. How do I make a View showing the current image position? Such as a series of white dots with a black under the current picture. If the current image of the first - the first black dot. Thanks.
Google has a training class answering your first question here. It shows you how to load a bitmap in the background using an AsyncTask and caching it both in memory with an LruCache and on the disk with a DiskLruCache (included in the BitmapFun.zip download found at the link) while displaying a ProgressBar until the image is downloaded
Can I use a different view(not ViewFlipper)?
The aforementioned example uses a ViewPager.
a series of white dots with a black under the current picture.
I do not know if there is such a view available from the Android SDK but this third party widget (Apache 2.0 license) seems to do what you want.
How i can keep link on ImageView and ProgressBar?
I am not sure I understand the question but if you are asking how you go from the ProgressBar (while the image is loading) to the ImageView then the answer is to use a FrameLayout with the ProgressBar and ImageView in it:
<FrameLayout ...> <ProgressBar ... /> <ImageView android:id="@+id/imageView" ... /> </FrameLayout>
(see image_detail_fragment.xml in the exercise for more details)
The ImageView will be drawn in front of the ProgressBar but as it will originally have no background and no image it will be transparent and the ProgressBar will be showing.
You then retrieve the ImageView from your code using its id and when you have loaded your image in a Bitmap you use:
Now that the ImageView has an image it will not be transparent anymore and the ProgressBar will not be showing (you can also add an id to the progress bar if you want to set it to View.GONE to optimise your layout).