[英]Setting Vollery ImgController with global variables extending application
我正在嘗試使用凌空從下一行從URL加載圖像:
Image.setImageUrl(url, ImgController.getInstance().getImageLoader());
但是ImgController無法解決。 我檢查發現,我需要在AndroidManifest.xml文件中注冊我的自定義應用程序上下文,並包含以下行:
<application android:name="ImgController" android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name">
但是我已經在使用與全局變量(擴展Application的類)不同的上下文,例如:
<application android:name_"example.example.name.Global" android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name">
所以這是我的問題,如何設置ImgController而不破壞我的Global變量類?
謝謝。
最終使用了Volley ImageRequest,效果很好。 這是代碼:
public void fetchBackgroundImage(String url){
ImageRequest imgRequest = new ImageRequest(url,
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
Drawable banner = new BitmapDrawable(bitmap);
findViewById(R.id.headerImage).setBackgroundDrawable(banner);
}
},256,88,null,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError ex) {
System.out.println(ex.getMessage().toString());
}
}
);
RequestQueue rq = Volley.newRequestQueue(this);
rq.add(imgRequest);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.