Java.IO.FileNotFoundException 从适配器读取资产文件时 Class - Xamarin

Java.IO.FileNotFoundException while reading assets file from adapter Class - Xamarin

我正在尝试将 Assets 中的图像添加到 imageView。我正在从适配器 class 执行此操作。我在现有文件上得到 Java.IO.FileNotFoundException

这是我的适配器class:

using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Java.IO;
using Android.Graphics;

namespace test2
{
    public class MyListViewAdapter : BaseAdapter<Person>
    {
        private List<Person> mItems;
        private Context mContext;
        private Button mButton;
        private Activity activity;
    public MyListViewAdapter(Context context, List<Person> items)
    {
        mItems = items;
        mContext = context;
        this.activity = (Activity)context;
    }
    public override int Count
    {
        get
        {
            return mItems.Count;
        }
    }
    public override long GetItemId(int position)
    {
        return position;
    }
    public override Person this[int position]
    {
        get
        {
            return mItems[position];
        }
    }
    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;
        if (row == null)
        {
            row = LayoutInflater.From(mContext).Inflate(Resource.Layout.listview_row, null, false);
        }

        /*
        some code
        */

        Android.Content.Res.AssetManager assets = mContext.Assets;
        ImageView imageViewStar1 = row.FindViewById<ImageView>(Resource.Id.imageViewStar1);
        var InStr = assets.Open("poi_star_empty.png"); //here is an exception
        Bitmap bitmap = BitmapFactory.DecodeStream(InStr);
        imageViewStar1.SetImageBitmap(bitmap);

        /*
        some code
        */

        return row;
    }


    private class ButtonClickListener : Java.Lang.Object, View.IOnClickListener
    {
        /*
        some code
        */
    }

} }

如何从非 activity class 读取此图像?

这就是我调用 MyListViewAdapter 构造函数的方式:

mAdapter = new MyListViewAdapter(this, mItems);

这是我的资产清单:

我做到了!对于我的资产,我必须将构建操作设置为 AndroidAsset 并且它有效

将文件复制到 xamarin.droid 中的资产文件夹,然后在文件的属性中 select 构建操作,然后是 AndroidAsset 然后像

一样访问它

var fd = global::Android.App.Application.Context.Assets.OpenFd(fileName);