从本地存储中显示imageview中的图像

时间:2017-09-23 10:17:48

标签: listview xamarin.android imageview

我正在开发一个xamarin android应用程序,其中我实现了一个列表视图。所以我需要将该图像显示到listview中,以便如何使用路径在imageview中显示图像。

我没有得到如何在xamarin.android

中显示文件路径中的图像

这是我的CustomAdaptor

internal class MyCustomListAdapter : BaseAdapter
{
    private List<AlbumTable> albm;
    private LayoutInflater mInflater;
    Context c;
    Dialog dialog;
    public MyCustomListAdapter(Context c,List<AlbumTable> albm)
    {
        this.albm = albm;
        this.c = c;
        mInflater = (LayoutInflater)c.GetSystemService(Context.LayoutInflaterService);

    }

    public override int Count
    {

        get
        {
            return albm.Count();
        }
    }

    public override Java.Lang.Object GetItem(int position)
    {
        return null;
    }

    public override long GetItemId(int position)
    {
        return long.Parse(albm[position].Id);
    }

    public override View GetView(int position, View view, ViewGroup parent)
    {
        Button btnDelete;

        ViewHolder1 holder = null;
        if (view == null)
        {
            view = mInflater.Inflate(Resource.Layout.inflate_album, null);
            holder = new ViewHolder1();
            holder.coverp = view.FindViewById<ImageView>(Resource.Id.sliderviewpager);
            btnDelete = view.FindViewById<Button>(Resource.Id.share_album);
            btnDelete.Focusable = false;
            btnDelete.FocusableInTouchMode = false;
            btnDelete.Clickable = true;
            btnDelete.Click += (object sender, EventArgs e) =>
            {

                Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(c);
                alert.SetTitle("Delete Album");
                alert.SetMessage("Are you really wnt to delete the Album");
                alert.SetCancelable(false);
                alert.SetPositiveButton("Yes", delegate {
                    DatabaseHelper db = new DatabaseHelper();
                    bool aa=db.DeleteFromTable(albm[position]);

                    if (aa)
                    {
                        Toast.MakeText(c, "Album Deleted Successfully", ToastLength.Short).Show();
                    }
                });
                alert.SetNegativeButton("No", delegate {
                    if (dialog.IsShowing)
                        dialog.Dismiss();
                });
                dialog = alert.Create();
                dialog.Show();

            };
        }
        else
        {
            btnDelete = view.FindViewById<Button>(Resource.Id.share_album);
            holder = view.Tag as ViewHolder1;
            btnDelete.Tag = position;

        }

        return view;
    }

我的getter setter方法如下

class AlbumTable
{

    [PrimaryKey]
    public string Id { get; set; }

    public string ZipFillPath { get; set; }

    public string CoverPhotoPath { get; set; }

    public string AlbumKey { get; set; }

    public string NoOfPages { get; set; }

    public string Email { get; set; }

    public string LastName { get; set; }

    public string FirstName { get; set; }

    public string City { get; set; }

    public string Address1 { get; set; }

    public string ZipPostalCode { get; set; }

    public string PhoneNumber { get; set; }

}

如何使用路径在imageview中显示图像。

1 个答案:

答案 0 :(得分:0)

  

如何使用路径在imageview中显示图像。

有一些第三方库可以很好地实现此功能,例如PicassoGlide

对于Picasso,有官方文档显示如何在Xamarin.Android项目中使用它:Binding a .JAR

然后你可以这样编码:

Picasso.With(this).Load(imageUrl).Into(imageView);