I have movies app and I tried to pass name and poster of each movie from MainActivity to DetailActivity after click on movie poster, and the name passed correctly with no problems but I have problem with poster
this is the code in MainActivity:
public void onClick(View v) {
int adapterPosition = getAdapterPosition();
Uri moviePoster = mMoviesItems.get(adapterPosition).getFullPosterPath();
String movieName = mMoviesItems.get(adapterPosition).getName();
mClickHandler.onClick(moviePoster, movieName);
}
and this is the code for DetailActivity:
private String moviePoster;
private String movieName;
private ImageView mMoviePoster;
private TextView mMovieName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mMovieName = (TextView) findViewById(R.id.tv_movie_name);
mMoviePoster = (ImageView) findViewById(R.id.iv_poster);
Intent intentThatStartedThisActivity = getIntent();
if (intentThatStartedThisActivity != null) {
if (intentThatStartedThisActivity.hasExtra("moviePoster")) {
moviePoster = intentThatStartedThisActivity.getStringExtra("moviePoster");
mMoviePoster.setImageDrawable(getResources().getDrawable(moviePoster));
}
if (intentThatStartedThisActivity.hasExtra("movieName")) {
movieName = intentThatStartedThisActivity.getStringExtra("movieName");
mMovieName.setText(movieName);
}
}
}
}
and this is the custom class where I build the method of posters:
public class MovieItem extends ArrayList<MovieItem> {
private String photo;
private String name;
public MovieItem(String poster_path, String original_title) {
this.photo = poster_path;
this.name = original_title;
}
public String getPhoto() {
return photo;
}
public String getName() {
return name;
}
public Uri getFullPosterPath() {
return Uri.parse("http://image.tmdb.org/t/p/")
.buildUpon()
.appendPath("w185")
.appendEncodedPath(getPhoto())
.build();
}
}
it's correct that I define it like Uri ?
and why I get error with getDrawable(moviePoster));
tells that
getDrawable (int) in Resources cannot be applied to (java.lang.String)