'How to fetch genre of a movie using its genre_ids from tmdb api in android
I'd like to use the tmdb api in Android to display the movie's genre, but the problem is that we have to first find the genre id before we can display the genre name, and I'm not able to display the genre id and the genre name. Please assist me. I am getting the genre from the TMDB documentation
This is what the genre list looks like
When i get movie information, I get the genre as "genre_ids": [28,878,35,10751,12]
I got a tip to say I have to map, but I am quite new to the programming world so I don't know how to.
How do I get the genres from the movie and map it with the list in the image above and make it show in my app as names and not numbers.
This is how I am getting the information into the app, it works with the details like the overview, poster path and so on but not the genre.
if (infos.containsKey("original_title")) {
title.setText(infos.get("original_title").toString());
}
else {
title.setText("");
}
if (infos.containsKey("overview")) {
info.setText(infos.get("overview").toString());
}
else {
info.setText("");
}
if (infos.containsKey("runtime")) {
length.setText(infos.get("runtime").toString().substring((int)(0), (int)(3)).concat("m"));
}
else {
length.setText("");
}
if (infos.containsKey("release_date")) {
year.setText(infos.get("release_date").toString().substring((int)(0), (int)(4)));
}
else {
year.setText("");
}
if (!infos.get("tagline").toString().equals("")) {
tags.setText("''".concat(infos.get("tagline").toString().concat("\"")));
}
else {
tags.setVisibility(View.GONE);
}
if (infos.containsKey("vote_average")) {
ratingbar1.setNumStars((int)5);
ratingbar1.setStepSize((float)0.1d);
ratingbar1.setRating((float)Double.parseDouble(infos.get("vote_average").toString()) / 2);
textview_rating.setText(infos.get("vote_average").toString());
}
else {
textview_rating.setVisibility(View.GONE);
ratingbar1.setVisibility(View.GONE);
}
if (infos.containsKey("vote_count")) {
number_if_voters.setText("(".concat(infos.get("vote_count").toString().concat(")")));
}
else {
number_if_voters.setVisibility(View.GONE);
}
if (infos.containsKey("popularity")) {
popu.setText(infos.get("popularity").toString());
}
else {
popu.setVisibility(View.GONE);
}
if (infos.containsKey("genre_ids")) {
genres.setText(infos.get("genre_ids").toString());
}
else {
genres.setVisibility(View.GONE);
}
Please Explain in detail.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|