title: Load bitmap in recyclerView from internalStorage with Asynctask
body: <p>i'm actually working in an Android app who need to downloading PNG from web and showing it in a recyclerView. The downloading part works fine same as the save in the internal storage. The problem is with the display, when i load it in AsyncTask in my onBindViewHolder, this isn't fluid..... and on AVD i have an exception something like resources not closed. So i will paste the adapter :</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.MyViewHolder&gt;{
  private static final String TAG = "MyAdapter";
  private List&lt;Item&gt; listItem = null;
  
  public MyAdapter(List&lt;Item&gt; listItem) {
      this.listItem = listItem;
  }
  
  @Override
  public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      // Log.d(logTag, "view group " + parent);
      View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row, parent, false);
      return new MyViewHolder(v);
  }
  
  @Override
  public void onBindViewHolder(final MyViewHolder holder, int position) {
      //Log.d(logTag, " bind " + position + " holder " + holder);
      final Item item = listItem.get(position);
  
      holder.position = position;
      //new LoadBitmap(position, holder).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, item.getId());
  }
  
  private class LoadBitmap extends AsyncTask&lt;String, Void, Bitmap&gt; {
      private MyViewHolder holder = null;
      private int position = 0;
  
      public LoadBitmap(int position, MyViewHolder holder) {
          this.holder = holder;
          this.position = position;
      }
  
      @Override
      protected Bitmap doInBackground(String... params) {
          File file = new File("/data/data/myapp/files", params[0]);
          FileInputStream fis = null;
          Bitmap bitmap = null;
          try {
              fis = new FileInputStream(file);
              bitmap = BitmapFactory.decodeStream(fis);
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } finally {
              if (fis != null) {
                  try {
                      fis.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
  
          return bitmap;
      }
  
      @Override
      protected void onPostExecute(Bitmap bitmap) {
          if (bitmap != null &amp;&amp; holder.position == position) {
              holder.imageView.setImageBitmap(bitmap);
          }
      }
  }
  
  
  @Override
  public int getItemCount() {
      return listItem.size();
  }
  
  
  public class MyViewHolder extends RecyclerView.ViewHolder {
      private ImageView imageView = null;
  
      int position = 0;
  
      public MyViewHolder(View itemView) {
          super(itemView);
          imageView = (ImageView) itemView.findViewById(R.id.imageView_item);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I try too with UI Thread :</p>
  
  <pre><code> holder.imageView.post(new Runnable() {
          @Override
          public void run() {
              File file = new File("/data/data/myapp/files", item.getId());
              FileInputStream fis = null;
              Bitmap bitmap = null;
              try {
                  fis = new FileInputStream(file);
                  bitmap = BitmapFactory.decodeStream(fis);
                  holder.imageView.setImageBitmap(bitmap);
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } finally {
                  if (fis != null) {
                      try {
                          fis.close();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                  }
              }
          }
      });
  </code></pre>
  
  <p>I hope it's clear enough and sorry for my english.
  Thanx.</p>
  
  <p>EDIT : 
  This fix work perfect</p>
  
  <pre><code>@Override
  public void onBindViewHolder(final MyViewHolder holder, int position) {
      Item item = listItem.get(position);
  
      holder.position = position;
      File file = new File("/data/data/myApp/files", item.getId());
      Picasso.with(holder.itemView.getContext()).load(file).resize(50,25).centerCrop().into(holder.imageView);
  }
  </code></pre>