title: GridView not refreshing after changing setting
body: <p>I am building this movie app that displays movies in a gridview on the main panel, then I can click them and display some information about that movie, also I have some settings to change the criteria of the movies displayed: popular, top rated or favorites. The favorites are a local collection saved in sharedPreferences chosen by the user.<br>
   Here is where it all happens:  </p>
  
  <pre><code>public class MovieFragment extends Fragment{
      public String[][] matrixMoviesInfo;
      public GridView gridView;
      public String[] mArrayImages;
      private String baseUrl;
      private String apiKey;
  
  public MovieFragment(){
      matrixMoviesInfo = new String[20][10];
      mArrayImages = new String[20];
      baseUrl = "http://api.themoviedb.org/3/movie/";
      apiKey = "?api_key=37068e0a72b2cc1751b4246899923ba7";
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      super.onCreateOptionsMenu(menu, inflater);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_main, container, false);
      gridView = (GridView) rootView.findViewById(R.id.gridview);
      gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                                  int position, long id) {
              Intent intent = new Intent(getActivity(), DetailActivity.class)
                      .putExtra(Intent.EXTRA_TEXT, matrixMoviesInfo[position]);
              intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
          }
      });
      return rootView;
  }
  
  private void setImages() {
      for(int i=0;i&lt;mArrayImages.length;i++){
          if(matrixMoviesInfo[i][0]!=null) {
              mArrayImages[i] = matrixMoviesInfo[i][0];
          }
      }
      gridView.setAdapter(null);
      gridView.setAdapter(new ImageAdapter(getActivity(), mArrayImages));
      Log.v(null, "SETIMAGESCALLED");
  }
  
  private void updateMovies() {
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
      String preference = prefs.getString(getString(R.string.pref_sortby_key), getString(R.string.pref_sortby_default));
      if(preference.toLowerCase().equals("favorites")){
          SharedPreferences preferences = getContext().getSharedPreferences("favorites_list", Context.MODE_PRIVATE);
          Map&lt;String, ?&gt; allEntries = preferences.getAll();
          String[] keyNames = new String[allEntries.size()];
          Log.v(null,"SIZE: "+allEntries.size());
          String[] keyValues;
          int iterator=0;
          for (Map.Entry&lt;String, ?&gt; entry : allEntries.entrySet()) {
              Log.v("KEY: " +entry.getKey(), "VALUE: "+entry.getValue().toString());
          }
          for (Map.Entry&lt;String, ?&gt; entry : allEntries.entrySet()) {
              if(entry.getKey()!=null) {
                  keyNames[iterator] = entry.getKey();
                  keyValues = entry.getValue().toString().split("#");
                  for (int i = 0; i &lt; 10; i++) {
                      Log.v("INDEX: " + i, " VALUES: " + keyValues[i]);
                      matrixMoviesInfo[iterator][i] = keyValues[i];
                  }
                  iterator++;
              }
          }
          setImages();
      }else{
          Log.v(null,"EXECUTETASK");
          new FetchMoviesTask().execute(baseUrl+preference.toLowerCase()+apiKey, "i");
      }
  }
  
  @Override
  public void onStart() {
      super.onStart();
      updateMovies();
  }
  
  public class FetchMoviesTask extends AsyncTask&lt;String, String, Void&gt; {
  
      private final String LOG_TAG = FetchMoviesTask.class.getSimpleName();
  
      private Void getMovieDetailsFromJson(String movieJSONstr) throws JSONException {
  
          final String OWM_RESULTS = "results";
          final String OWM_ID = "id";
          final String OWM_POSTERPATH = "poster_path";
          final String OWM_TITLE = "original_title";
          final String OWM_OVERVIEW = "overview";
          final String OWM_USERRATING = "vote_average";
          final String OWM_RELEASEDATE = "release_date";
  
          JSONObject movieJson = new JSONObject(movieJSONstr);
          JSONArray movieArray = movieJson.getJSONArray(OWM_RESULTS);
  
          for(int i = 0; i &lt; movieArray.length(); i++) {
              JSONObject movieObj = movieArray.getJSONObject(i);
              matrixMoviesInfo[i][0] = movieObj.getString(OWM_POSTERPATH);
              matrixMoviesInfo[i][1] = movieObj.getString(OWM_ID);
              matrixMoviesInfo[i][2] = movieObj.getString(OWM_TITLE);
              matrixMoviesInfo[i][3] = movieObj.getString(OWM_OVERVIEW);
              matrixMoviesInfo[i][4] = movieObj.getString(OWM_USERRATING);
              matrixMoviesInfo[i][5] = movieObj.getString(OWM_RELEASEDATE);
          }
          for(int i=0;i&lt;20;i++) {
              new FetchMoviesTask().execute(baseUrl + matrixMoviesInfo[i][1] + "/reviews" + apiKey, Integer.toString(i));
              new FetchMoviesTask().execute(baseUrl + matrixMoviesInfo[i][1] + "/videos" + apiKey, "v");
          }
          Log.v(null,"GETMOVIEDETAILS");
          return null;
      }
  
      private Void getMovieReviewsFromJson(String movieJSONstr, String position) throws JSONException{
  
          int pos = Integer.parseInt(position);
          final String OWM_RESULTS = "results";
          final String OWM_AUTHOR = "author";
          final String OWM_CONTENT = "content";
          final String OWM_TOTALRESULTS = "total_results";
  
          JSONObject movieJson = new JSONObject(movieJSONstr);
          JSONArray movieArray = movieJson.getJSONArray(OWM_RESULTS);
          int numberOfResults = Integer.parseInt(movieJson.getString(OWM_TOTALRESULTS));
  
          if(numberOfResults &gt;= 1) {
              matrixMoviesInfo[pos][6] = movieArray.getJSONObject(0).getString(OWM_AUTHOR);
              matrixMoviesInfo[pos][7] = movieArray.getJSONObject(0).getString(OWM_CONTENT);
          }
          if(numberOfResults &gt; 1) {
              matrixMoviesInfo[pos][8] = movieArray.getJSONObject(1).getString(OWM_AUTHOR);
              matrixMoviesInfo[pos][9] = movieArray.getJSONObject(1).getString(OWM_CONTENT);
          }
  
          return null;
      }
  
      private Void getMovieVideosFromJson(String movieJSONstr){
  
          return null;
      }
  
      @Override
      protected Void doInBackground(String... params) {
  
          HttpURLConnection urlConnection = null;
          BufferedReader reader = null;
  
          String movieJSONstr = null;
  
          try{
              URL url = new URL(params[0]);
              urlConnection = (HttpURLConnection) url.openConnection();
              urlConnection.setRequestMethod("GET");
              urlConnection.connect();
  
              InputStream inputStream = urlConnection.getInputStream();
              StringBuffer buffer = new StringBuffer();
              if(inputStream == null){
                  return null;
              }
              reader = new BufferedReader(new InputStreamReader(inputStream));
  
              String line;
              while((line = reader.readLine()) != null){
                  buffer.append(line + "\n");
              }
  
              if(buffer.length() == 0){
                  movieJSONstr = 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("MovieFragment", "Error closing stream", e);
                  }
              }
          }
  
          try{
              if(params[1].equals("i")){
                  Log.v(null,"EXECUTEGETMOVIEDETAILS");
                  return getMovieDetailsFromJson(movieJSONstr);
              }
              else {
                  if (params[1].equals("v")){
                      return getMovieVideosFromJson(movieJSONstr);}
                  else{
                      return getMovieReviewsFromJson(movieJSONstr, params[1]);}
              }
          }catch (JSONException e) {
              Log.e(LOG_TAG, e.getMessage(), e);
              e.printStackTrace();
          }
  
          return null;
      }
  
      @Override
      protected void onPostExecute(Void aVoid) {
          String[] mArrayImages = new String[20];
          for(int i=0;i&lt;20;i++){
              mArrayImages[i] = matrixMoviesInfo[i][0];
          }
          gridView.setAdapter(new ImageAdapter(getActivity(), mArrayImages));
          Log.v(null, "IMAGES SET GRIDVIEW REFRESHED");
      }
  }  
  </code></pre>
  
  <p><b>Class Explanation:</b><br>
  There is 2 paths:    </p>
  
  <p>Popular or TopRated: starts on method UpdateMovies, then executes the asynctask to fetch data from the api, followed by the execution of the getMoviesFromJson that extracts all the information related to all movies. Then it ends on onPostExecute that populates the gridview with the ImageAdapter.    </p>
  
  <p>Favorites: starts on method UpdateMovies, here it fetchs the data from sharedpreferences and populates the array with that data, then it calls the method setImages to populate the gridView with the ImageAdapter.  </p>
  
  <p><b>Here is my problem:</b> when I am displaying the popular movies and change the setting to favorites, it displays the right movies on the sharedpreferences but it is not "cleaning" the remaining ones from the gridview.<br>
  Also how can I adjust the scroll of the gridview to match the cells it has (when there is no movie to populate a cell, I hide it like this:</p>
  
  <pre><code>  imageView.setVisibility(View.GONE);  
  </code></pre>