我有下面的代码:
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
imageView.setImageBitmap(bMap);
但是获得以下的错误:
The method getResources() is undefined for the type ImageDownloader
如何访问资源呢?
我有下面的代码:
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
imageView.setImageBitmap(bMap);
但是获得以下的错误:
The method getResources() is undefined for the type ImageDownloader
如何访问资源呢?
在你的 ImageDownloader 类中创建一个新的 Constructor
public ImageDownloader(Activity mActivity){
// create a class level activity object in your ImageDownloader class.
activity = mActivity;
}
现在需要改变下载代码:
Bitmap bMap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.icon);
imageView.setImageBitmap(bMap);