ssuukk
ssuukk

Reputation: 8410

Refreshing Gallery object when content bitmap is updated

I have a class derived from android.widget.Gallery and a class derived from BaseAdapter that has createBitmap overriden. The gallery will show a bunch of images that get downloaded from the Internet, but since user may choose not to watach all of them, I download each image only when necessary (i.e. when it gets displayed by Gallery). So on first call createBitmap returns a default "downloading image" icon and downloading of proper image gets scheduled. My activity gets notified when the image is ready. But I don't know how to force refresh of currently visible gallery object (although it's enough to scroll it out of the view and get back to it to see downloaded image). notifyDataSetChanged() gives no joy...

Any ideas?

Upvotes: 0

Views: 332

Answers (1)

Greg
Greg

Reputation: 196

Supposedly when your activity is notified, it knows the position of the item, or some sort of identifier. You should be able to retrieve the view and set the Bitmap to it (which will refresh the particular view.

The way to identify the view for a given identifier is to attach the identifier to the view with the setTag function. Then you can loop through the Gallery children and find the view :

for(int i=0 ; i<mParent.getChildCount();i++){
  View view = mParent.getChildAt(i);
  if(view!=null && view.getTag().equals(yourIdentifier)){
    return view;
  }
}

And the loop should be quick, because AdapterViews only keep a limited number of views and recycle them.

Upvotes: 1

Related Questions