title: RecyclerView get View by position
body: <p>I have a <code>RecyclerView</code> and each <code>CardView</code> contains a <code>TextView</code> and an <code>ImageView</code>. Whenever I click an item, I want to set the image visibility to VISIBLE and to set the previous clicked item image's visibility to INVISIBLE.</p>
  
  <p>This is my Adapter class :</p>
  
  <pre><code>public class CategoryAdapter extends RecyclerView.Adapter&lt;CategoryAdapter.ViewHolder&gt;{
  private Context context;
  private List&lt;Category&gt; lista;
  private LayoutInflater layoutInflater;
  private IncomeCategoryActivity activity;
  
  private static final int CATEGORY_REQUEST=6;
  private static final int ITEM_EDIT=1;
  private static final int ITEM_DELETE=2;
  private static final int EDIT_REQUEST=7;
  
  private int current_pos=-1;
  
  
  public CategoryAdapter(List&lt;Category&gt; lista, Context context, IncomeCategoryActivity activity) {
      this.context = context;
      this.lista = lista;
      this.activity=activity;
      layoutInflater=LayoutInflater.from(context);
  }
  
  @Override
  public CategoryAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view=layoutInflater.inflate(R.layout.category_layout, parent, false);
      ViewHolder viewHolder=new ViewHolder(view, activity);
  
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder(CategoryAdapter.ViewHolder holder, int position) {
      holder.imageView.setImageURI(lista.get(position).getUri());
      holder.textView.setText(lista.get(position).getCategory());
      holder.position = position;
      holder.category=lista.get(position);
  
      if(holder.category.isChecked()==true){
          holder.imageViewCheck.setVisibility(View.VISIBLE);
          current_pos=position;
      } else {
          holder.imageViewCheck.setVisibility(View.INVISIBLE);
      }
  }
  
  @Override
  public int getItemCount() {
      return lista.size();
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener{
      public ImageView imageView;
      public TextView textView;
      public ImageView imageViewCheck;
      public int position;
      public Category category;
      public IncomeCategoryActivity activity;
  
      public ViewHolder(View itemView, IncomeCategoryActivity activity) {
          super(itemView);
          this.activity=activity;
  
          imageView=itemView.findViewById(R.id.customCategoryImageView);
          textView=itemView.findViewById(R.id.customCategoryTextView);
          imageViewCheck=itemView.findViewById(R.id.customCheckImageView);
  
          itemView.setOnClickListener(this);
          itemView.setOnCreateContextMenuListener(this);
  
      }
  
      @Override
      public void onClick(View v) {
          String aux=textView.getText().toString();
          if(aux=="CATEGORIE NOUĂ"){
              Intent intent=new Intent(context, CustomIncomeActivity.class);
              activity.startActivityForResult(intent, CATEGORY_REQUEST);
          }
          else{
              imageViewCheck.setVisibility(View.VISIBLE);
              int pozitie_check=getLayoutPosition();
              Intent intent=new Intent(context, AddIncomeActivity.class);
              intent.putExtra("categorie_venit", aux);
              intent.putExtra("position_check", pozitie_check);
              activity.setResult(Activity.RESULT_OK, intent);
              activity.finish();
          }
  
      }
  
      @Override
      public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
          menu.setHeaderTitle("Selectează acțiunea");
          MenuItem edit=menu.add(0, ITEM_EDIT, 0, "Modifică");
          MenuItem delete=menu.add(0, ITEM_DELETE, 0, "Șterge");
  
          edit.setOnMenuItemClickListener(this);
          delete.setOnMenuItemClickListener(this);
      }
  
      @Override
      public boolean onMenuItemClick(MenuItem item) {
          int position=getLayoutPosition();
          if (item.getGroupId() == 0) {
              if(item.getItemId()==ITEM_EDIT){
                  Category category=lista.get(position);
                  Intent intent=new Intent(activity, CustomIncomeActivity.class);
                  intent.putExtra("edit_icon", category.getUri());
                  intent.putExtra("edit_category", category.getCategory());
                  intent.putExtra("list_position", position);
                  activity.startActivityForResult(intent, EDIT_REQUEST);
              }
              else if(item.getItemId()==ITEM_DELETE){
                  lista.remove(position);
                  notifyDataSetChanged();
              }
      }
      return true;
  
  }
  </code></pre>
  
  <p>At this moment, whenever I click an item, there are two images VISIBLE on the <code>RecyclerView</code>: the clicked item's image and the previous clicked item's image. I think I need to get the previous View by its position and to manually set the visibility to INVISIBLE.</p>