Macya
V2EX  ›  Android

Glide 使用 SimpleTarget 加载网络图片

  •  
  •   Macya · Apr 18, 2016 · 18753 views
    This topic created in 3704 days ago, the information mentioned may be changed or developed.

    最近在学习 Glide ,在使用 SimpleTarget 的时候, Android Studio 给出了这样一个警告

    Unchecked method 'into(Y)' invocation

    实际运行是没问题的 但是这个警告是什么意思呢?

    代码:

    Glide.with(getApplicationContext())
        .load(internetUrl)
        .error(R.mipmap.ic_launcher)
        .into(simpleTarget);
        
    simpleTarget = new SimpleTarget<Drawable>(){
    	@Override
    	public void onResourceReady(Drawable resource, GlideAnimation<? super Drawable> glideAnimation) {
    		imageView_top.setImageDrawable(resource);
    	}
    };
    
    2 replies    2016-04-19 09:37:57 +08:00
    EdiTurn
        1
    EdiTurn  
       Apr 19, 2016
    into 接收的参数是 Y extends Target<TranscodeType>,猜测你 simpleTarget 的声明没有指定泛型。

    另,在本例中, TranscodeType 需要是 GldieDrawable (见 load 的返回类型)。
    Macya
        2
    Macya  
    OP
       Apr 19, 2016
    @EdiTurn simpleTarget 的声明确实没有指定泛型,这个案例是按照某个翻译的 blog 对着做的,没有想到这点,加上泛型之后,警告消失了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   923 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 21:35 · PVG 05:35 · LAX 14:35 · JFK 17:35
    ♥ Do have faith in what you're doing.