title: Making a popular movies app using GridView, Adapters and Picasso
body: <p>I am trying to make an app where I want my app, on launch, to display a grid of popular movie posters. The movie posters are downloaded from TheMovieDataBase API. I then use Picasso to load the images. For the GridView I am also using a custom adapter. I am not able to understand how to do it. Here is what I have done up till now.
  //OLD CODE REMOVED</p>
  
  <p>Please tell me what I have to do so that my app looks like this: <a href="https://lh6.googleusercontent.com/BLcEAGgyiHtsGq8wbilmqj00A2yPFyu1rnrnXl6LrzhdOPK9xJylzzXs-F5iOO6g01wguJVJ9cTXqOerCdmcF3IfjoUx9ySvcIepFMSLq00eWJ-rkede-NlDalD3K5cMZbKYJsc" rel="nofollow">App mock</a></p>
  
  <p>This app is a part of the Udacity's Developing in Android course and here is the implementation guide provided by them: <a href="https://docs.google.com/document/d/1gtXUu1nzLGWrGfVCD6tEA0YHoYA9UNyT2yByqjJemp8/pub?embedded=true" rel="nofollow">Implementation Guide</a></p>
  
  <p>EDIT:
  As some people have marked my question as "too broad" I re-stating my question. The following code requests movie details from the TMDB api and then displays a grid of the movie names in text. Now I want to display movie posters instead of the names in a grid. The poster path is stored in the moviePosterPath String array. How do I do this?</p>
  
  <pre><code>public class MainActivityFragment extends Fragment {
      ArrayAdapter&lt;String&gt; mMovieAdapter;
      String[] movieId, movieTitle, movieReleaseDate, movieVoteAverage, movieOverview, moviePosterPath;
      public MainActivityFragment() {
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_main, container, false);
  
  
          GridView listView = (GridView) rootView.findViewById(R.id.gridview_movies);
          mMovieAdapter = new ArrayAdapter&lt;String&gt;(getActivity(),
                  R.layout.item_movies,
                  R.id.image_view_movie,
                  new ArrayList&lt;String&gt;());
          listView.setAdapter(mMovieAdapter);
  
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
          {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l)
              {
                  Intent intent = new Intent(getActivity(), DetailActivity.class);
                  String forecast = mMovieAdapter.getItem(i);
                  String send = "Overview" + movieOverview[i] + "\n" + "Release Date" + movieReleaseDate[i];
                  intent.putExtra(Intent.EXTRA_TEXT, send);
                  startActivity(intent);
              }
          });
          return rootView;
      }
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setHasOptionsMenu(true);
      }
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          // Inflate the menu; this adds items to the action bar if it is present.
          inflater.inflate(R.menu.moviefragment, menu);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
          if (id == R.id.action_refresh) {
              updateMovie();
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      public void onStart()
      {
          super.onStart();
          updateMovie();
      }
  
      private void updateMovie() {
          FetchMovieTask movieTask = new FetchMovieTask();
          movieTask.execute();
      }
  
      class FetchMovieTask extends AsyncTask&lt;Void, Void, String[]&gt; {
          private final String LOG_TAG = FetchMovieTask.class.getSimpleName();
  
          @Override
          protected String[] doInBackground(Void... params) {
              HttpURLConnection urlConnection = null;
              BufferedReader reader = null;
  
              // Will contain the raw JSON response as a string.
              String movieJsonStr = null;
  
              try {
                  URL url = new URL("http://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&amp;api_key=c20129fdf73b5df3ab44548ad7f73586");
  
                  urlConnection = (HttpURLConnection) url.openConnection();
                  urlConnection.setRequestMethod("GET");
                  urlConnection.connect();
  
                  // Read the input stream into a String
                  InputStream inputStream = urlConnection.getInputStream();
                  StringBuffer buffer = new StringBuffer();
                  if (inputStream == null) {
                      // Nothing to do.
                      return null;
                  }
                  reader = new BufferedReader(new InputStreamReader(inputStream));
  
                  String line;
                  while ((line = reader.readLine()) != null) {
  
                      buffer.append(line + "\n");
                  }
  
                  if (buffer.length() == 0) {
                      // Stream was empty.  No point in parsing.
                      return null;
                  }
                  movieJsonStr = buffer.toString();
  
              } catch (IOException e) {
                  Log.e(LOG_TAG, "Error ", e);
                  return null;
              } finally {
                  if (urlConnection != null) {
                      urlConnection.disconnect();
                  }
                  if (reader != null) {
                      try {
                          reader.close();
                      } catch (final IOException e) {
                          Log.e(LOG_TAG, "Error closing stream", e);
                      }
                  }
              }
              try {
                  return getMovieDataFromJson(movieJsonStr);
              } catch (JSONException j) {
                  Log.e(LOG_TAG, "JSON Error", j);
              }
              return null;
          }
  
          private String[] getMovieDataFromJson(String forecastJsonStr)
                  throws JSONException {
              JSONObject movieJson = new JSONObject(forecastJsonStr);
              JSONArray movieArray = movieJson.getJSONArray("results");
              movieId = new String[movieArray.length()];
              movieTitle = new String[movieArray.length()];
              movieReleaseDate = new String[movieArray.length()];
              movieVoteAverage = new String[movieArray.length()];
              movieOverview = new String[movieArray.length()];
              moviePosterPath = new String[movieArray.length()];
              for (int i = 0; i &lt; movieArray.length(); i++)
              {
                  JSONObject movie = movieArray.getJSONObject(i);
                  movieId[i] = movie.getString("id");
                  movieTitle[i] = movie.getString("original_title");
                  movieReleaseDate[i] = movie.getString("release_date");
                  movieVoteAverage[i] = movie.getString("vote_average");
                  movieOverview[i] = movie.getString("overview");
                  moviePosterPath[i] = movie.getString("poster_path");
              }
              return movieTitle;
          }
  
          @Override
          protected void onPostExecute(String[] strings)
          {
              super.onPostExecute(strings);
              mMovieAdapter.clear();
              mMovieAdapter.addAll(strings);
          }
      }
  }
  </code></pre>