title: RecyclerView - Get view at particular position
body: <p>I have an activity with a <code>RecyclerView</code> and an <code>ImageView</code>. I am using the <code>RecyclerView</code> to show a list of images horizontally. When I click on an image in the <code>RecyclerView</code> the <code>ImageView</code> in the activity should show a bigger picture of the image. So far everything works fine.</p>
  
  <p>Now there are two more <code>ImageButtons</code> in the activity: <code>imageButton_left</code> and <code>imageButton_right</code>. When I click on <code>imageButton_left</code>, the image in the <code>ImageView</code> should turn left and also, the thumbnail in the <code>RecyclerView</code> should reflect this change. Similar is the case with <code>imageButton_right</code>.</p>
  
  <p>I am able to rotate the <code>ImageView</code>. But, how can I rotate the thumbnail in the <code>RecyclerView</code>? How can I get the <code>ViewHolder</code>'s <code>ImageView</code>? </p>
  
  <p>Code:</p>
  
  <p>Activity XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerview"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp" /&gt;
  
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"
          android:orientation="vertical"&gt;
  
          &lt;ImageView
              android:id="@+id/original_image"
              android:layout_width="200dp"
              android:layout_height="200dp"
              android:scaleType="fitXY"
              android:src="@drawable/image_not_available_2" /&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="10dp"
              android:gravity="center_horizontal"
              android:orientation="horizontal"&gt;
  
  
              &lt;ImageButton
                  android:id="@+id/imageButton_left"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginRight="20dp"
                  android:background="@drawable/rotate_left_icon" /&gt;
  
              &lt;ImageButton
                  android:id="@+id/imageButton_right"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:background="@drawable/rotate_right_icon" /&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My Activity Code:</p>
  
  <pre><code>public class SecondActivity extends AppCompatActivity implements IRecyclerViewClickListener {
  
  
      RecyclerView mRecyclerView;
      LinearLayoutManager mLayoutManager;
      RecyclerViewAdapter mRecyclerViewAdapter;
      List&lt;String&gt; urls = new ArrayList&lt;String&gt;();
      ImageView mOriginalImageView;
      ImageButton mLeftRotate, mRightRotate;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_second);
          urls.clear();
  
          mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
          mLayoutManager = new LinearLayoutManager(this, android.support.v7.widget.LinearLayoutManager.HORIZONTAL, false);
          mLayoutManager.setOrientation(android.support.v7.widget.LinearLayoutManager.HORIZONTAL);
          mRecyclerView.setLayoutManager(mLayoutManager);
          mRecyclerViewAdapter = new RecyclerViewAdapter(this, urls);
          mRecyclerView.setAdapter(mRecyclerViewAdapter);
  
          mOriginalImageView = (ImageView) findViewById(R.id.original_image);
          mLeftRotate = (ImageButton) findViewById(R.id.imageButton_left);
          mLeftRotate.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  mOriginalImageView.setRotation(mOriginalImageView.getRotation() - 90);
              }
          });
  
  
          mRightRotate = (ImageButton) findViewById(R.id.imageButton_right);
          mRightRotate.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  mOriginalImageView.setRotation(mOriginalImageView.getRotation() + 90);
              }
          });
  
          Intent intent = getIntent();
          if (intent != null) {
  
              String portfolio = intent.getStringExtra("portfolio");
  
              try {
  
                  JSONArray jsonArray = new JSONArray(portfolio);
  
                  for (int i = 0; i &lt; jsonArray.length(); i++) {
  
                      JSONObject jsonObject = jsonArray.getJSONObject(i);
  
                      String url = jsonObject.getString("url");
                      urls.add(url);
                  }
  
                  Log.d(Const.DEBUG, "URLs: " + urls.toString());
  
                  mRecyclerViewAdapter.notifyDataSetChanged();
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
          }
  
      }
  
  
      @Override
      public void onItemClick(int position) {
          Picasso.with(this).load(urls.get(position)).into(mOriginalImageView);
      }
  }
  </code></pre>
  
  <p>My Custom Adapter for RecyclerView:</p>
  
  <pre><code>public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.ViewHolder&gt; {
  
      Context context;
      List&lt;String&gt; mUrls = new ArrayList&lt;String&gt;();
  
      IRecyclerViewClickListener mIRecyclerViewClickListener;
  
      public int position;
  
      public int getPosition() {
          return position;
      }
  
      public void setPosition(int position) {
          this.position = position;
      }
  
  
  
      public RecyclerViewAdapter(Context context, List&lt;String&gt; urls) {
          this.context = context;
          this.mUrls.clear();
          this.mUrls = urls;
  
          Log.d(Const.DEBUG, "Urls Size: " + urls.size());
          Log.d(Const.DEBUG, urls.toString());
  
          if (context instanceof IRecyclerViewClickListener)
              mIRecyclerViewClickListener = (IRecyclerViewClickListener) context;
          else
              Log.d(Const.DEBUG, "Implement IRecyclerViewClickListener in Activity");
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(context).inflate(R.layout.item_horizontal_recyclerview, parent, false);
          ViewHolder holder = new ViewHolder(view);
          return holder;
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
          Picasso.with(context).load(mUrls.get(position)).into(holder.mImageView);
      }
  
      @Override
      public int getItemCount() {
          return mUrls.size();
      }
  
  
      public void rotateThumbnail() {
  
  
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
          public ImageView mImageView;
          public View v;
  
          public ViewHolder(View v) {
              super(v);
              v.setTag(getAdapterPosition());
              v.setOnClickListener(this);
              this.mImageView = (ImageView) v.findViewById(R.id.image);
          }
  
          @Override
          public void onClick(View v) {
              this.v = v;
              mIRecyclerViewClickListener.onItemClick(getAdapterPosition());
          }
      }
  
  
  }
  </code></pre>