如何解决无法将图像视图传递到Glide
我尝试在 ImageView菜单
上从 Glide 加载图像但它在我的imageView上没有显示图像;
我的图像视图ID是约会对象
从url中的JSON对象加载图像。
在::-
上显示错误
Glide.with(this).load(url).into(menagerie);
下面是完整的 代码:-
public void loadMore() {
String url = "http://my-json-feed";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.get,url,null,new
Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
String url = null;
try {
url = response.getString("url");
} catch (JSONException e) {
e.printStackTrack();
}
Glide.with(this).load(url).into(menagerie);
}
}
}
解决方法
您在with.(this)
处出错
使用getApplicationContext()
代替this
您在.into(menagerie)
处出错
您永远不要传递ID
您需要初始化变量并将ID传递给它
像这样->
ImageView ImageView;
...
.
.
onCreate()...{
.
.
ImageView=(ImageView)view.findViewById(R.id.menagerie);
.
.
然后您应该执行此操作->
Glide.with(getApplicationContext())
.load(url)
.into(ImageView);
,
改用getApplicationContext(),例如Glide.with(getApplicationContext())。load(imageUrl).into(imageView);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。