我有下面的代碼:
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);