2016-11-11 64 views
-1

我正在開發一個應用程序,顯示歌曲的所有專輯封面圖片。 所以我使用glide來加載和緩存圖像,並避免OutofMemoryError。滑行不起作用?這是錯誤:

這是AlbumAdapter我getView方法:

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    RelativeLayout albumsLay = (RelativeLayout)songInf.inflate 
      (R.layout.album_layout, parent, false); 
    ImageView coverView = (ImageView)albumsLay.findViewById(R.id.song_cover); 

    //get song using position 
    Song currSong = songs.get(position); 

    if (Drawable.createFromPath(currSong.getCover()) != null) { 
     Drawable img = Drawable.createFromPath(currSong.getCover()); 
        Glide.with(this).load(img).into(coverView); 

    } 

    albumsLay.setTag(position); 
    return albumsLay; 
} 

這是錯誤我得到:

Error:(77, 18) error: no suitable method found for with(AlbumAdapter) 
method Glide.with(android.support.v4.app.Fragment) is not applicable 
(actual argument AlbumAdapter cannot be converted to android.support.v4.app.Fragment by method invocation conversion) 
method Glide.with(android.app.Fragment) is not applicable 
(actual argument AlbumAdapter cannot be converted to android.app.Fragment by method invocation conversion) 
method Glide.with(FragmentActivity) is not applicable 
(actual argument AlbumAdapter cannot be converted to FragmentActivity by method invocation conversion) 
method Glide.with(Activity) is not applicable 
(actual argument AlbumAdapter cannot be converted to Activity by method invocation conversion) 
method Glide.with(Context) is not applicable 
(actual argument AlbumAdapter cannot be converted to Context by method invocation conversion) 
+0

發佈你的滑翔配置 – Raju

回答

1

你需要通過上下文與Glide

Glide.with(this) // will not work 

通行證上下文從您的Activity/FragmentAlbumAdapter

Context mContext; 
public AlbumAdapter(Context context){ 
    mContext = context; 
} 

,並且使用帶有Glide

Glide.with(mContext) 

這種情況下,如果你有Activity,那麼你需要使用new AlbumAdapter(ActivityName.this)Fragment你需要使用new AlbumAdapter(getActivity())

+0

它的工作表示感謝。但我得到這個錯誤: 11-11 11:05:55.866 11120-11120/com.xrobot.andrew.musicalbumsE/AndroidRuntime:致命例外:主 進程:com.xrobot.andrew.musicalbums,PID:11120 java .lang.OutOfMemoryError:嘗試拋出OutOfMemoryError時拋出OutOfMemoryError;沒有可用的堆棧跟蹤 – xRobot