【问题标题】:Picasso.with().invalidate(file) error: can not resolve method invalidate(java.io.File)Picasso.with().invalidate(file) 错误:无法解析方法 invalidate(java.io.File)
【发布时间】:2016-02-28 16:09:15
【问题描述】:

在我的应用程序中,我使用了 picasso 库,但是当我集成到我的代码中时,它将以红色显示 .invalidate(file) 。怎么解决?

请找到以下代码以获取更多参考:

        FutureCallback<File> writeNewFileCallback = new FutureCallback<File>() {
        @Override
        public void onCompleted(Exception e, File file) {
            if (e == null) { // Success


                Picasso.with(MyApp.this.getActivity()).invalidate(file);


                Transformation transformation = new     RoundedTransformationBuilder()
                        .scaleType(ImageView.ScaleType.FIT_XY)
                        .borderColor(Color.parseColor("#77e5e5e5"))
                        .borderWidthDp(2)
                        .cornerRadiusDp(15)
                        .oval(false)
                        .build();}

什么时候改成:

`Picasso.with(this).invalidate(file);`

“this”将是未知的。

【问题讨论】:

标签: android picasso


【解决方案1】:

对于与用户界面相关的调用,请使用 Activity 上下文。

请参阅 Reto Meier 的解释:Using Application context everywhere?

【讨论】:

    【解决方案2】:

    这很容易解决。就这样吧,

    Picasso.with(getApplicationContext()).invalidate(file);
    

    with() 方法将 Context 作为参数,当您在 Activity 中时,将 this 设置为可以正常工作。

    但在您的情况下,您在匿名内部类中使用 this,因此 this 指的是该特定类而不是您的 Context。

    希望对你有帮助。

    【讨论】:

    • 谢谢大家。我的问题是我的毕加索版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多