Search code examples
androidandroid-studioandroid-intentandroid-imageviewandroid-image

How to show image path in image view


Dears

I am Making a movie app that have two activities first activity have gridview that

shows grid of movie posters and whenever you click on any poster it will take you

to the other activity which is suppose to show the poster of the movie you clicked on

and detail text.

what is my problem?

when the second activity starts the movie detail is displayed but the poster is

not showing, how to display an image using an image path like this

"6bCplVkhowCjTHXWv49UjRPn0eK.jpg"? below the related code:

First Activity:

  gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i,   long l) {

            String movieDetailText = "ID:" + movieId[i] + " \n" + "Title:\n"  + movieTitle[i] + "\n"
                    + "Over View:\n" + movieOverview[i] + "\n" + "Release   Date:\n" +
                    movieReleaseDate[i] + "\n" + "Rating:\n" +  movieVoteAverage[i];
            String movieDetailImage = moviePosterPath[i];

            Intent intent = new Intent(getActivity(),DetailActivity.class);
            intent.putExtra(Intent.EXTRA_TEXT,movieDetailText);
            intent.putExtra("image_path", movieDetailImage);
            startActivity(intent);




        }
       });

Second Activity:

   Intent intent = getActivity().getIntent();
        if (intent != null && intent.hasExtra(Intent.EXTRA_TEXT)) {
            String movieDetail = intent.getStringExtra(Intent.EXTRA_TEXT);
            ((TextView) rootView.findViewById(R.id.detail_text))
                    .setText(movieDetail);
            String posterImage = intent.getStringExtra("image_path");
            Bitmap bitmap = BitmapFactory.decodeFile(posterImage);
                    ((ImageView) rootView.findViewById(R.id.detail_image))
                    .setImageBitmap(bitmap);

Solution

  • I needed to add the following to fix my issue:

                String imagePath = intent.getStringExtra("image_path");
                String posterImage = "http://image.tmdb.org/t/p/w185/" + imagePath;