public void UpdatedImage(Uri uri) { //// this is how the iOS version behaves, but on Android it seems to result in 'wrong images' //context.RunOnUiThread(() => { // var drawable = ImageLoader.DefaultRequestImage(uri, null); // if (drawable == null) { // //TODO: this shouldn't happen, if the UpdatedImage callback comes, it should ALWAYS be there // ImageLoader.LogDebug(" ???? " + ImageName(uri.ToString())); // } else { // imageView.SetImageDrawable(drawable); // } //}); //return; ImageLoader.LogDebug(" updt " + ImageName(uri.ToString())); // imageViews are re-used (because the View/cells they live in are re-used), // so just check the 'current' tag for the imageView matches the Url we are // updating it to, if not then the image has been cached but is not required right now. if (imageView.Tag.ToString() == uri.ToString()) { context.RunOnUiThread(() => { var drawable = ImageLoader.DefaultRequestImage(uri, null); if (drawable == null) { //TODO: this shouldn't happen, if the UpdatedImage callback comes, it should ALWAYS be there ImageLoader.LogDebug(" xxxx " + ImageName(uri.ToString())); } else { imageView.SetImageDrawable(drawable); } }); } else { ImageLoader.LogDebug( String.Format(" miss w{0}, g{1}" // wanted, but got , ImageName(imageView.Tag.ToString()) , ImageName(uri.ToString()) ) ); // hit-and-hope, maybe the image we really want is already in the cache/filesystem var uri1 = new Uri(imageView.Tag.ToString()); context.RunOnUiThread(() => { var drawable = ImageLoader.DefaultRequestImage(uri1, this); if (drawable != null) { imageView.SetImageDrawable(drawable); } }); } }
public override View GetView(int position, View convertView, ViewGroup parent) { ViewHolder holder; var view = convertView; var item = items [position]; TextView tvTextView; if (view == null) { view = inflater.Inflate(Resource.Layout.gridviewitems, parent, false); view.SetTag(Resource.Id.picture, view.FindViewById(Resource.Id.picture)); view.SetTag(Resource.Id.text, view.FindViewById(Resource.Id.text)); holder = new ViewHolder(); holder.Name = (TextView)view.GetTag(Resource.Id.text); //holder.Image = (ImageViewAsync)view.GetTag (Resource.Id.picture); holder.Image = (SquareImageView)view.GetTag(Resource.Id.picture); view.Tag = holder; } else { holder = (ViewHolder)view.Tag; } ivImageView = (ImageView)view.GetTag(Resource.Id.picture); tvTextView = (TextView)view.GetTag(Resource.Id.text); //ivImageView.SetImageResource (item.DrawableId); tvTextView.Text = item.Name; var uri = new Uri(item.ImgUrl); var iw = new ImageWrapper(ivImageView, context); ivImageView.Tag = uri.ToString(); try { var drawable = ImageLoader.DefaultRequestImage(uri, iw); if (drawable != null) // use it { ivImageView.SetImageDrawable(drawable); } else // we're just going to grab it ourselves and not wait for the callback from ImageLoader { ivImageView.SetImageResource(item.DrawableId); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(view); }