在我的主页面中,我正在调用AsyncTask,它是自己的类。
new DownloadFileAsync(context, icon, resultp.get(PublicProfilePage.REVIEWCREATORFBOOKID),"300").execute();
下面是我的AsyncTask。我正在读JSON试图获取图像的URL。一旦我捕获了该URL,我就使用ImageLoader对其进行缓存,但它不起作用。
public class DownloadFileAsync extends AsyncTask<Void, Void, String> {
//private Context context;
CircularImageView bmImage;
ImageLoader imageLoader;
String fbook_id;
String jsonobject;
String image_size;
String size_url;
public DownloadFileAsync(Context context, CircularImageView bmImage, String fbook_id, String size)
{
//this.context = context;
this.bmImage = bmImage;
this.fbook_id = fbook_id;
this.image_size = size;
//Image Loader Initialization
imageLoader = new ImageLoader(context);
if(image_size.equalsIgnoreCase("150")) {
size_url = "https://graph.facebook.com/v2.1/" + fbook_id + "/picture?redirect=0&height=150&width=150";
}else if(image_size.equalsIgnoreCase("300")) {
size_url = "https://graph.facebook.com/v2.1/" + fbook_id + "/picture?redirect=0&height=300&width=300";
}
}
protected String doInBackground(Void... urls) {
String result = null;
String queryResponse = null;
String resultTwo = null;
// Create a new HttpClient and Post Header
HttpClient httpclientBankCheck = new DefaultHttpClient();
HttpGet httppostBankCheck = new HttpGet(size_url);
try {
// Execute HTTP Post Request
HttpResponse responseBankCheck = httpclientBankCheck.execute(httppostBankCheck);
HttpEntity responseText = responseBankCheck.getEntity();
queryResponse = EntityUtils.toString(responseText);
// Retrive JSON Objects from the given website URL in
// JSONfunctions.class
jsonobject = queryResponse;
// Locate the array name
JSONObject arr = new JSONObject(jsonobject);
result = arr.getString("data");
JSONObject arrTwo = new JSONObject(result);
resultTwo = arrTwo.getString("url");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return resultTwo;
}
protected void onPostExecute(String resultTwo) {
//bmImage.setImageBitmap(result);
imageLoader.DisplayImage(resultTwo, bmImage);
}
}
如果我将URL硬编码到主页面内的ImageLoader中,它确实有效。问题是我正在使用带有ImageLoader的AsyncTask吗?它不应该是对的吗?
非常感谢帮助!
-M