【问题标题】:Setting Vollery ImgController with global variables extending application使用扩展应用程序的全局变量设置 Vollery ImgController
【发布时间】:2015-06-23 15:29:28
【问题描述】:

我正在尝试使用 volley 从下一行的 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 android:name_"example.example.name.Global" android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name">

所以这是我的问题,如何设置 ImgController 而不篡改我的全局变量类?

谢谢。

【问题讨论】:

    标签: java android image global-variables android-volley


    【解决方案1】:

    最终使用 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      相关资源
      最近更新 更多