我試圖從資產添加圖像到imageView。我從適配器類來做這件事。我正在獲取現有文件上的Java.IO.FileNotFoundException。Java.IO.FileNotFoundException從適配器類讀取資產文件 - Xamarin
這裏是我的適配器類:
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
*/
}
}}
我怎樣才能讀取非活動課這一形象?
這就是我怎麼稱呼MyListViewAdapter構造:
mAdapter = new MyListViewAdapter(this, mItems);
這裏是我的資產清單: