title: How to show multiple images in a RecyclerView?
body: <p>I'm trying to develop a gallery app in android studio and I'm using a RecyclerView Layout to load efficiently the images on the screen but whenever I scroll down, after a few images the app crush. The error I get is <strong>java.lang.OutOfMemoryError</strong> so I thought that I was making a mistake with the class adapter but I couldn't find any error (I follow the steps given in the android documentation <a href="https://developer.android.com/guide/topics/ui/layout/recyclerview" rel="nofollow noreferrer">Create a List with RecyclerView </a>). I tried to show a thumbnail of each image instead of the actual image but after scrolling down a few images the app crush and I get the <strong>The application may be doing too much work on its main thread</strong> error</p>
  
  <p>I'll leave the code of the adapter class. If you need more code example or more info tell me please!</p>
  
  <p>Pd: Sorry I'm not clear, my English is pretty bad and I don't have experience asking questions here plus I this is my first app in android.</p>
  
  <p>public class MyAdapter extends RecyclerView.Adapter {</p>
  
  <pre><code>public class ViewHolder extends RecyclerView.ViewHolder {
  
      public ImageView image;
  
      public ViewHolder(@NonNull View itemView) {
          super(itemView);
          image = (ImageView) itemView.findViewById(R.id.IMAGEN);
      }
  }
  
  private ArrayList&lt;File&gt; images = new ArrayList&lt;&gt;();
  private Activity activity;
  
  public MyAdapter(ArrayList&lt;File&gt; images, Activity activity){
      this.images = images;
      this.activity = activity;
  }
  
  @NonNull
  @Override
  public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
      View v = activity.getLayoutInflater().inflate(R.layout.image_item, viewGroup, false);
      ViewHolder vh = new ViewHolder(v);
      return vh;
  }
  
  @Override
  public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
      //Bitmap myBitmap = BitmapFactory.decodeFile(images.get(position).getAbsolutePath());
      //holder.image.setImageBitmap(myBitmap);
      Picasso.get().load(images.get(position)).resize(300,300).centerCrop().into(holder.image);
  }
  
  @Override
  public void onViewRecycled(@NonNull ViewHolder holder) {
      super.onViewRecycled(holder);
      holder.image.setImageBitmap(null);
  }
  
  @Override
  public int getItemCount() {
      return images.size();
  }
  </code></pre>
  
  <p>}</p>