我试图将图像填充为列表视图内容中相对布局的背景。这里是从json数组获取图像路径。所以我已经在ArrayAdapter类中完成了这一切。
这是我在getView方法中的代码
// Get merchant cover image path
String coverImagePath = membershipResource.getMerCoverImagePath();
String fullImagePath = "http://new.inspirenetz.com/in-resources/"+coverImagePath;
// Get filename from the path
String imageFileName = fullImagePath.substring(fullImagePath.lastIndexOf("/")+1);
// Set merchant cover image
Drawable drawable = imageOperations(context, fullImagePath,imageFileName);
resizableImageView.setBackgroundDrawable(drawable);
这是下载图片的目的
public Drawable imageOperations(Context context, String url, String saveFilename){
try{
InputStream is = (InputStream)this.fetch(url);
Drawable d = Drawable.createFromStream(is, saveFilename);
return d;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
但是我得到了 android.os.NetworkOnMainThreadException ,我已经引用了以下链接How to fix android.os.NetworkOnMainThreadException?,但我不知道如何在我的代码中执行此操作
任何人都可以帮助我。谢谢!