我正在我的应用程序中执行位图调整大小。我有一个名为Bitmap Images的文件夹,它具有启动位图调整大小的功能。但是在我的适配器(这行代码)hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(getResources(),news[position].Image,100,100));
中,第一个参数getResource
被引发为错误。缺少什么?
public class MyAdapter : RecyclerView.Adapter
{
private JavaList<News> news;
public MyAdapter(JavaList<News> news)
{
this.news = news;
}
//binding data to views
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
MyHolder hold = holder as MyHolder;
hold.Comment.Text = news[position].Comment;
//hold.Img.SetImageResource(news[position].Image);
hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(getResources(),news[position].Image,100,100));
}
答案 0 :(得分:0)
问题是你没有通过Context
。要访问getResources()
,您必须通过Context
。所以修改你的适配器类。
public class MyAdapter : RecyclerView.Adapter
{
private JavaList<News> news;
private Context context;
public MyAdapter(JavaList<News> news, Context context)
{
this.news = news;
this.context = context;
}
......
//Then in your OnBindViewHolder you can call getResources
.....
hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(context.getResources(),news[position].Image,100,100));
}