3

I am new to Xamarin Android Application.I use Picasso component to cache and download Images and It works fine.
Picasso.With (this.Activity).Load ("Here I pass Url").Into (imageview); Now I am using MvvmCross binding like:

<Mvx.MvxImageView
   android:layout_width="120dp"
   android:layout_height="140dp"
   android:id="@+id/ProductImageView"
   android:scaleType="fitXY"
   local:MvxBind="ImageUrl URL" />

Here URL is a string which I set in Viewmodel.My problem is, it downloads image but can not cache that image like picasso does.Can anyone suggest me what to do? How to use Picasso to bind and cache image ?

Dhruv Gohil
  • 842
  • 11
  • 34

2 Answers2

4

There's nothing magic about MvxImageView - it's class a class that inherits from ImageView and exposes a public string ImageUrl property that you can use in binding.

You don't have to use MvxImageView - you can create your own PicassoImageView and expose a property:

private string _i;
public string ImageUrl 
{
    get { return _i; }
    set {
        if (_i == value) return;
        _i = value;
        if (string.IsNullOrEmpty(value)) {
           // what do you want to do here? clear the view? use a placeholder?
           return;
        }
        Picasso.With (this.Context).Load (_i).Into (this);
    }
}

That sort of thing should work...

...With bonus points if you blog/write about how you get this working and what you learn along the way (or if you publish a nuget package that others can use)

Stuart
  • 66,722
  • 7
  • 114
  • 165
2

You can cache an image with Picasso without loading it in any ImageViewers like this:

Picasso. with(Context). load(ImageFile.Url). into(null);

But im not sure how you can use this later.

You can try your own implementation of caching, it's easy, check this article

CDrosos
  • 2,418
  • 4
  • 26
  • 49