Am trying to populate the images as background of relative layout in the list view content. here am getting the image path from the json array.so i have done this and all in the ArrayAdapter class.
Here my code which is in getView method
// 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);
this is what am doing for download the image
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;
}
but am getting android.os.NetworkOnMainThreadException for this i have referred the following link, How to fix android.os.NetworkOnMainThreadException? but i don't know how to do this in my code
can anyone please help me. Thanks.!