Glide doesn't work ? This is the error:
Glide doesn't work ? This is the error:
我正在开发一个应用程序,可以显示所有歌曲的专辑封面图片。
所以我使用 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)
您需要使用 Glide
传递上下文
Glide.with(this) // will not work
将上下文从您的 Activity/Fragment
传递给 AlbumAdapter
Context mContext;
public AlbumAdapter(Context context){
mContext = context;
}
并将该上下文与 Glide
一起使用
Glide.with(mContext)
如果你有 Activity
那么你需要使用 new AlbumAdapter(ActivityName.this)
而对于 Fragment
你需要使用 new AlbumAdapter(getActivity())
更新版本的 glide,
RequestManager manager = Glide.with(imageView);
manager.load(imageUrl).into(imageView);
我正在开发一个应用程序,可以显示所有歌曲的专辑封面图片。 所以我使用 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)
您需要使用 Glide
Glide.with(this) // will not work
将上下文从您的 Activity/Fragment
传递给 AlbumAdapter
Context mContext;
public AlbumAdapter(Context context){
mContext = context;
}
并将该上下文与 Glide
Glide.with(mContext)
如果你有 Activity
那么你需要使用 new AlbumAdapter(ActivityName.this)
而对于 Fragment
你需要使用 new AlbumAdapter(getActivity())
更新版本的 glide,
RequestManager manager = Glide.with(imageView);
manager.load(imageUrl).into(imageView);