title: Display Image from clicked item of Recyclerview
body: <p>I am trying to get the image string from the recyclerview, that is already populated, so that I can display the image on the imageview of another activity. Here, I get the path(url) of image using jsoup:</p>
  
  <pre><code>org.jsoup.nodes.Document document = Jsoup.connect(URL).get();
                  for(Element e : document.select("img[src]"))
                  {
                      Elements imgScr = e.select("img[src]");
                      String elements = imgScr.attr("src");
                      String text = imgScr.attr("alt");
                      String desc = imgScr.attr("title");
  
                      arrayList.add(new FeedItem(text, elements, desc));
                  }
  </code></pre>
  
  <p>into <code>elements</code> variable and then storing it into arraylist. I want to get that path(url) of image(stored in <code>elements</code>) so that I can display that image in another activity. I tried to retrieve that url from the <code>arrayList</code> using this method:</p>
  
  <pre><code>public String getImageUrl(int pos)
      {
          return arrayList.get(pos).getThumb();
      }
  </code></pre>
  
  <p>but a <code>IndexOutOfBound</code> exception is thrown, saying that the index(pos) is invalid and size of <code>arrayList</code> is 0. I don't know why it is saying that the list has size 0, while the Recyclerview gets pouplated and shows the data which I parsed using <code>jsoup</code>. Please help me out guys, I am stuck on this for three days.</p>
  
  <p>Okay the complete code is here:
  This the main activity which shows the recyclerview</p>
  
  <pre><code>public class RestaurantsAndCafesActivity extends Activity {
  
  public static final String URL = "http://192.168.8.102:80/jay.html";
  
  private RecyclerView mRecyclerView;
  private RCRecyclerAdapter adapter;
  public String imgUrl;
  //public List&lt;FeedItem&gt; feedItemList;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.reyclerview_layout);
  
      /* Initialize RecyclerView */
      mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
      mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  
      //parseResult();
  
      new getDataAsyncTask().execute();
  
      final GestureDetector mGestureDetector = new GestureDetector(RestaurantsAndCafesActivity.this, new GestureDetector.SimpleOnGestureListener() {
  
          @Override public boolean onSingleTapUp(MotionEvent e) {
              return true;
          }
  
      });
  
  
      mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
          @Override
          public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
              View child = recyclerView.findChildViewUnder(motionEvent.getX(),motionEvent.getY());
              if(child!=null &amp;&amp; mGestureDetector.onTouchEvent(motionEvent)){
  
                  Toast.makeText(RestaurantsAndCafesActivity.this,"Clicked Number "+recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show();
                  imgUrl = new getDataAsyncTask().getImageUrl(recyclerView.getChildPosition(child));
                  Intent intent = new Intent(RestaurantsAndCafesActivity.this, GetReviewActivity.class);
                  intent.putExtra("Imgurl" ,imgUrl);
                  startActivity(intent);
                  return true;
              }
              return false;
          }
  
          @Override
          public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
  
          }
      });
  }
  public class getDataAsyncTask extends AsyncTask&lt;Void,Void,Void&gt;{
       ArrayList&lt;FeedItem&gt; arrayList = new ArrayList&lt;&gt;();
  
      public String getImageUrl(int pos)
      {
          return arrayList.get(pos).getThumb();
      }
  
      @Override
      protected Void doInBackground(Void... params) {
          try {
                  org.jsoup.nodes.Document document = Jsoup.connect(URL).get();
                  for(Element e : document.select("img[src]"))
                  {
                      Elements imgScr = e.select("img[src]");
                      String elements = imgScr.attr("src");
                      String text = imgScr.attr("alt");
                      String desc = imgScr.attr("title");
  
                      arrayList.add(new FeedItem(text, elements, desc));
                  }
              }
          catch(IOException e)
              {
              e.printStackTrace();
              }
          return null;
      }
  
      ProgressDialog progressDialog;
      @Override
      protected void onPreExecute()
      {
          progressDialog = ProgressDialog.show(RestaurantsAndCafesActivity.this,"Loading","Please Wait",true,false);
      }
      @Override
      protected void onPostExecute(Void aVoid) {
          progressDialog.dismiss();
          adapter = new RCRecyclerAdapter(getApplicationContext(),arrayList);
          mRecyclerView.setAdapter(adapter);
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>These are the adapter, viewholder and data classes:</p>
  
  <pre><code>public class RCRecyclerAdapter extends RecyclerView.Adapter&lt;RCRecyclerViewListRowHolder&gt; {
  
  
  private List&lt;FeedItem&gt; feedItemList;
  private Context mContext;
  
  public RCRecyclerAdapter(Context context, List&lt;FeedItem&gt; feedItemList) {
      this.feedItemList = feedItemList;
      this.mContext = context;
  }
  
  @Override
  public RCRecyclerViewListRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
      View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.restaurants_cafes_layout_card, null);
      RCRecyclerViewListRowHolder mh = new RCRecyclerViewListRowHolder(v);
  
      return mh;
  }
  
  @Override
  public void onBindViewHolder(RCRecyclerViewListRowHolder RCRecyclerViewListRowHolder, int i){
  
      FeedItem feedItem = feedItemList.get(i);
  
      Picasso.with(mContext).load(feedItem.getThumb()
      ).error(R.drawable.placeholder).placeholder(R.drawable.placeholder).into(RCRecyclerViewListRowHolder.thumbnail);
      RCRecyclerViewListRowHolder.title.setText(feedItemList.get(i).title);
      RCRecyclerViewListRowHolder.desc.setText(feedItemList.get(i).desc);
  }
  
  @Override
  public int getItemCount() {
      return (null != feedItemList ? feedItemList.size() : 0);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>viewholder:</p>
  
  <pre><code>public class RCRecyclerViewListRowHolder extends RecyclerView.ViewHolder {
  public ImageView thumbnail;
  public TextView title;
  public TextView desc;
  //Context context;
  
  public RCRecyclerViewListRowHolder(View view) {
      super(view);
      this.thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
      this.title = (TextView) view.findViewById(R.id.title);
      this.desc = (TextView) view.findViewById(R.id.desc);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>data:</p>
  
  <pre><code>public class FeedItem {
  
  public String title;
  public String thumb;
  public String desc;
  
  public FeedItem(String title, String thumb , String desc) {
      this.title = title;
      this.thumb = thumb;
      this.desc = desc;
  }
  
  public String getThumb() {
      return thumb;
  }
  </code></pre>
  
  <p>}</p>