title: Change image resource when clicking on ImageView inside the RecyclerView
body: <p>I'm trying to change my device's image resource inside the recyclerview at the specific position whenever i click at it (click at the image, not the item). I tried to put setOnClickListener() inside the onBindViewHolder() method but only the last item affected. <a href="https://i.stack.imgur.com/DTBoH.png" rel="nofollow noreferrer">here is my recycler view</a></p>
  
  <p>here is my Adapter:</p>
  
  <pre><code>public class Device_RV_Adapter extends RecyclerView.Adapter&lt;Device_View_Holder&gt; {
  
  List&lt;Device_Data&gt; list= Collections.emptyList();
  Context context;
  
  public Device_RV_Adapter(List&lt;Device_Data&gt; list,Context context){
      this.list=list;
      this.context = context;
  }
  @Override
  public Device_View_Holder onCreateViewHolder(ViewGroup parent, int viewType) {
      View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.device_row_layout,parent,false);
      Device_View_Holder holder = new Device_View_Holder(v);
      return holder;
  }
  
  @Override
  public void onBindViewHolder(final Device_View_Holder holder, final int position) {
  
      holder.device_id.setText(list.get(position).device_id);
      holder.home.setText(list.get(position).home_id);
      holder.room.setText(list.get(position).room);
      holder.current.setText(list.get(position).current);
      holder.switch_key.setImageResource(list.get(position).switch_key);
      holder.device.setTag(position);
      holder.device.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              int pos = (int)v.getTag();
              if(list.get(pos).flag==true){
                  list.get(pos).flag = false;
              }
              else if(list.get(pos).flag==false){
                  list.get(pos).flag = true;
              }
              notifyDataSetChanged();
          }
  
      });
  
      if(list.get(position).flag == true)
          holder.device.setImageResource(R.drawable.fan_off);
      else if(list.get(position).flag==false)
          holder.device.setImageResource(R.drawable.fan_on);
  }
  
  @Override
  public int getItemCount() {
      return list.size();
  }
  @Override
  public void onAttachedToRecyclerView(RecyclerView recyclerView){
      super.onAttachedToRecyclerView(recyclerView);
  }
  public void insert(int position,Device_Data device_data){
      list.add(position,device_data);
      notifyItemInserted(position);
  }
  public void remove(Device_Data device_data){
      int position = list.indexOf(device_data);
      list.remove(position);
      notifyItemRemoved(position);
  }
  </code></pre>
  
  <p>My ViewHolder:</p>
  
  <pre><code>public class Device_View_Holder extends RecyclerView.ViewHolder{
  
  CardView cv;
  TextView device_id,home,room,current;
  public static ImageView device, switch_key;
  boolean flag;
  public Device_View_Holder(View itemView) {
      super(itemView);
      cv=(CardView)itemView.findViewById(R.id.device_cv);
      device_id=(TextView)itemView.findViewById(R.id.device_id);
      home=(TextView)itemView.findViewById(R.id.home_id);
      room=(TextView)itemView.findViewById(R.id.room);
      current=(TextView)itemView.findViewById(R.id.current);
      device=(ImageView)itemView.findViewById(R.id.device_img);
      switch_key=(ImageView)itemView.findViewById(R.id.switch_key);
  }
  </code></pre>
  
  <p>And my Data class:</p>
  
  <pre><code>public class Device_Data {
  public String device_id,home_id,room,current;
  public int device,switch_key;
  boolean flag;
  public Device_Data(String device_id, String home_id, String room, String current,int device,int switch_key,boolean flag){
      this.device_id=device_id;
      this.home_id=home_id;
      this.room=room;
      this.current=current;
      this.device=device;
      this.switch_key=switch_key;
      this.flag=flag;
  }
  </code></pre>
  
  <p>When I click to the device's image, if it's on (flag=true), changed to "fan_off". If it's off, change to "fan_on". Just like a switch. Can anyone help me with this situation? Thanks in advance...</p>