How to display image in a listview from json response in android
Hi in the below code am displaying data from json response using retrofit library.
using recylerview am displaying title,id,albumid as well as image.all are displaying except image .
But how to display image from url. can any one please help me
this is my adapter class.
.java
public class RecyclerViewAdapterForAlbum extends RecyclerView.Adapter<RecyclerViewAdapterForAlbum.ViewHolder> {
private List<UserAlbum> item;
Context context ;
public RecyclerViewAdapterForAlbum(Context context, List<UserAlbum> item ) {
Log.d("123", "RecyclerViewAdapter");
this.item = item;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d("123", "onCreateViewHolder");
View view = LayoutInflater.from(context).inflate(R.layout.activity_second, null);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.d("123", "onBindViewHolder");
holder.user_id.setText(String.valueOf(item.get(position).getId()));
holder.album_id.setText(String.valueOf(item.get(position).getAlbumId()));
holder.title.setText(item.get(position).getTitle());
//Bitmap getBitMapFromUrl=null;
holder.imageForText.setImageResource(item.get(position).getThumbnailUrl());
}
@Override
public int getItemCount() {
Log.d("123", "getItemCount");
return item.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView album_id, user_id,title;
public ImageView imageForText;
public ViewHolder(View itemView) {
super(itemView);
Log.d("123", "ViewHolder");
user_id = (TextView) itemView.findViewById(R.id.user_id);
album_id=(TextView)itemView.findViewById(R.id.album_id);
title=(TextView)itemView.findViewById(R.id.title);
imageForText=(ImageView)itemView.findViewById(R.id.img_id);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// int pos = getAdapterPosition();
// int userID=item.get(pos).getId();
// Intent myIntent = new Intent(v.getContext(), SecondActivity.class);
// myIntent.putExtra("userId",userID);
// context.startActivity(myIntent);
}
});
}
}
}
android retrofit imageurl
add a comment |
Hi in the below code am displaying data from json response using retrofit library.
using recylerview am displaying title,id,albumid as well as image.all are displaying except image .
But how to display image from url. can any one please help me
this is my adapter class.
.java
public class RecyclerViewAdapterForAlbum extends RecyclerView.Adapter<RecyclerViewAdapterForAlbum.ViewHolder> {
private List<UserAlbum> item;
Context context ;
public RecyclerViewAdapterForAlbum(Context context, List<UserAlbum> item ) {
Log.d("123", "RecyclerViewAdapter");
this.item = item;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d("123", "onCreateViewHolder");
View view = LayoutInflater.from(context).inflate(R.layout.activity_second, null);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.d("123", "onBindViewHolder");
holder.user_id.setText(String.valueOf(item.get(position).getId()));
holder.album_id.setText(String.valueOf(item.get(position).getAlbumId()));
holder.title.setText(item.get(position).getTitle());
//Bitmap getBitMapFromUrl=null;
holder.imageForText.setImageResource(item.get(position).getThumbnailUrl());
}
@Override
public int getItemCount() {
Log.d("123", "getItemCount");
return item.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView album_id, user_id,title;
public ImageView imageForText;
public ViewHolder(View itemView) {
super(itemView);
Log.d("123", "ViewHolder");
user_id = (TextView) itemView.findViewById(R.id.user_id);
album_id=(TextView)itemView.findViewById(R.id.album_id);
title=(TextView)itemView.findViewById(R.id.title);
imageForText=(ImageView)itemView.findViewById(R.id.img_id);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// int pos = getAdapterPosition();
// int userID=item.get(pos).getId();
// Intent myIntent = new Intent(v.getContext(), SecondActivity.class);
// myIntent.putExtra("userId",userID);
// context.startActivity(myIntent);
}
});
}
}
}
android retrofit imageurl
You only have the url of the image in the son. You need to fetch the actual image first. I'd recommend using a library like Picasso
– user8886048
Nov 14 '18 at 11:27
You can use picasso , or Glide
– Rumit Patel
Nov 14 '18 at 11:29
4
Possible duplicate of Load image from url
– ADM
Nov 14 '18 at 11:32
add a comment |
Hi in the below code am displaying data from json response using retrofit library.
using recylerview am displaying title,id,albumid as well as image.all are displaying except image .
But how to display image from url. can any one please help me
this is my adapter class.
.java
public class RecyclerViewAdapterForAlbum extends RecyclerView.Adapter<RecyclerViewAdapterForAlbum.ViewHolder> {
private List<UserAlbum> item;
Context context ;
public RecyclerViewAdapterForAlbum(Context context, List<UserAlbum> item ) {
Log.d("123", "RecyclerViewAdapter");
this.item = item;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d("123", "onCreateViewHolder");
View view = LayoutInflater.from(context).inflate(R.layout.activity_second, null);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.d("123", "onBindViewHolder");
holder.user_id.setText(String.valueOf(item.get(position).getId()));
holder.album_id.setText(String.valueOf(item.get(position).getAlbumId()));
holder.title.setText(item.get(position).getTitle());
//Bitmap getBitMapFromUrl=null;
holder.imageForText.setImageResource(item.get(position).getThumbnailUrl());
}
@Override
public int getItemCount() {
Log.d("123", "getItemCount");
return item.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView album_id, user_id,title;
public ImageView imageForText;
public ViewHolder(View itemView) {
super(itemView);
Log.d("123", "ViewHolder");
user_id = (TextView) itemView.findViewById(R.id.user_id);
album_id=(TextView)itemView.findViewById(R.id.album_id);
title=(TextView)itemView.findViewById(R.id.title);
imageForText=(ImageView)itemView.findViewById(R.id.img_id);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// int pos = getAdapterPosition();
// int userID=item.get(pos).getId();
// Intent myIntent = new Intent(v.getContext(), SecondActivity.class);
// myIntent.putExtra("userId",userID);
// context.startActivity(myIntent);
}
});
}
}
}
android retrofit imageurl
Hi in the below code am displaying data from json response using retrofit library.
using recylerview am displaying title,id,albumid as well as image.all are displaying except image .
But how to display image from url. can any one please help me
this is my adapter class.
.java
public class RecyclerViewAdapterForAlbum extends RecyclerView.Adapter<RecyclerViewAdapterForAlbum.ViewHolder> {
private List<UserAlbum> item;
Context context ;
public RecyclerViewAdapterForAlbum(Context context, List<UserAlbum> item ) {
Log.d("123", "RecyclerViewAdapter");
this.item = item;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d("123", "onCreateViewHolder");
View view = LayoutInflater.from(context).inflate(R.layout.activity_second, null);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.d("123", "onBindViewHolder");
holder.user_id.setText(String.valueOf(item.get(position).getId()));
holder.album_id.setText(String.valueOf(item.get(position).getAlbumId()));
holder.title.setText(item.get(position).getTitle());
//Bitmap getBitMapFromUrl=null;
holder.imageForText.setImageResource(item.get(position).getThumbnailUrl());
}
@Override
public int getItemCount() {
Log.d("123", "getItemCount");
return item.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView album_id, user_id,title;
public ImageView imageForText;
public ViewHolder(View itemView) {
super(itemView);
Log.d("123", "ViewHolder");
user_id = (TextView) itemView.findViewById(R.id.user_id);
album_id=(TextView)itemView.findViewById(R.id.album_id);
title=(TextView)itemView.findViewById(R.id.title);
imageForText=(ImageView)itemView.findViewById(R.id.img_id);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// int pos = getAdapterPosition();
// int userID=item.get(pos).getId();
// Intent myIntent = new Intent(v.getContext(), SecondActivity.class);
// myIntent.putExtra("userId",userID);
// context.startActivity(myIntent);
}
});
}
}
}
android retrofit imageurl
android retrofit imageurl
asked Nov 14 '18 at 11:25
jyothi chandrajyothi chandra
277
277
You only have the url of the image in the son. You need to fetch the actual image first. I'd recommend using a library like Picasso
– user8886048
Nov 14 '18 at 11:27
You can use picasso , or Glide
– Rumit Patel
Nov 14 '18 at 11:29
4
Possible duplicate of Load image from url
– ADM
Nov 14 '18 at 11:32
add a comment |
You only have the url of the image in the son. You need to fetch the actual image first. I'd recommend using a library like Picasso
– user8886048
Nov 14 '18 at 11:27
You can use picasso , or Glide
– Rumit Patel
Nov 14 '18 at 11:29
4
Possible duplicate of Load image from url
– ADM
Nov 14 '18 at 11:32
You only have the url of the image in the son. You need to fetch the actual image first. I'd recommend using a library like Picasso
– user8886048
Nov 14 '18 at 11:27
You only have the url of the image in the son. You need to fetch the actual image first. I'd recommend using a library like Picasso
– user8886048
Nov 14 '18 at 11:27
You can use picasso , or Glide
– Rumit Patel
Nov 14 '18 at 11:29
You can use picasso , or Glide
– Rumit Patel
Nov 14 '18 at 11:29
4
4
Possible duplicate of Load image from url
– ADM
Nov 14 '18 at 11:32
Possible duplicate of Load image from url
– ADM
Nov 14 '18 at 11:32
add a comment |
3 Answers
3
active
oldest
votes
Using Picasso:
Add this line to your app-level build.gradle
file.
implementation 'com.squareup.picasso:picasso:2.71828'
And you can simply set image to ImageView
by:
Picasso.get().load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
Using Glide:
Add these lines to your app-level build.gradle
file.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
And you can simply set image to ImageView
by:
GlideApp.with(this).load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
add a comment |
You can use library for that, like Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
To use it :
Picasso.get().load("IMG URL").into(YOURIMAGEVIEW);
add a comment |
You have to use such type of libaray like picasso or universal image loader etc for load image on Your ImageView like in this I am using picaso
implementation 'com.squareup.picasso:picasso:2.71828'
Picasso.get().load(item.get(position).getThumbnailUrl()).into(imageForText);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299107%2fhow-to-display-image-in-a-listview-from-json-response-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using Picasso:
Add this line to your app-level build.gradle
file.
implementation 'com.squareup.picasso:picasso:2.71828'
And you can simply set image to ImageView
by:
Picasso.get().load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
Using Glide:
Add these lines to your app-level build.gradle
file.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
And you can simply set image to ImageView
by:
GlideApp.with(this).load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
add a comment |
Using Picasso:
Add this line to your app-level build.gradle
file.
implementation 'com.squareup.picasso:picasso:2.71828'
And you can simply set image to ImageView
by:
Picasso.get().load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
Using Glide:
Add these lines to your app-level build.gradle
file.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
And you can simply set image to ImageView
by:
GlideApp.with(this).load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
add a comment |
Using Picasso:
Add this line to your app-level build.gradle
file.
implementation 'com.squareup.picasso:picasso:2.71828'
And you can simply set image to ImageView
by:
Picasso.get().load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
Using Glide:
Add these lines to your app-level build.gradle
file.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
And you can simply set image to ImageView
by:
GlideApp.with(this).load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
Using Picasso:
Add this line to your app-level build.gradle
file.
implementation 'com.squareup.picasso:picasso:2.71828'
And you can simply set image to ImageView
by:
Picasso.get().load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
Using Glide:
Add these lines to your app-level build.gradle
file.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
And you can simply set image to ImageView
by:
GlideApp.with(this).load(item.get(position).getThumbnailUrl()).into(holder.imageForText);
answered Nov 14 '18 at 11:33
Rumit PatelRumit Patel
1,79242435
1,79242435
add a comment |
add a comment |
You can use library for that, like Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
To use it :
Picasso.get().load("IMG URL").into(YOURIMAGEVIEW);
add a comment |
You can use library for that, like Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
To use it :
Picasso.get().load("IMG URL").into(YOURIMAGEVIEW);
add a comment |
You can use library for that, like Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
To use it :
Picasso.get().load("IMG URL").into(YOURIMAGEVIEW);
You can use library for that, like Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
To use it :
Picasso.get().load("IMG URL").into(YOURIMAGEVIEW);
answered Nov 14 '18 at 11:28
BenjaminBenjamin
929
929
add a comment |
add a comment |
You have to use such type of libaray like picasso or universal image loader etc for load image on Your ImageView like in this I am using picaso
implementation 'com.squareup.picasso:picasso:2.71828'
Picasso.get().load(item.get(position).getThumbnailUrl()).into(imageForText);
add a comment |
You have to use such type of libaray like picasso or universal image loader etc for load image on Your ImageView like in this I am using picaso
implementation 'com.squareup.picasso:picasso:2.71828'
Picasso.get().load(item.get(position).getThumbnailUrl()).into(imageForText);
add a comment |
You have to use such type of libaray like picasso or universal image loader etc for load image on Your ImageView like in this I am using picaso
implementation 'com.squareup.picasso:picasso:2.71828'
Picasso.get().load(item.get(position).getThumbnailUrl()).into(imageForText);
You have to use such type of libaray like picasso or universal image loader etc for load image on Your ImageView like in this I am using picaso
implementation 'com.squareup.picasso:picasso:2.71828'
Picasso.get().load(item.get(position).getThumbnailUrl()).into(imageForText);
answered Nov 14 '18 at 11:32
Rashpal SinghRashpal Singh
526213
526213
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299107%2fhow-to-display-image-in-a-listview-from-json-response-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You only have the url of the image in the son. You need to fetch the actual image first. I'd recommend using a library like Picasso
– user8886048
Nov 14 '18 at 11:27
You can use picasso , or Glide
– Rumit Patel
Nov 14 '18 at 11:29
4
Possible duplicate of Load image from url
– ADM
Nov 14 '18 at 11:32