title: RecyclerView: keep changing data during scroll
body: <p>I have a RecyclerView. Each row has a switch button, I click on the switch to change its state.
  when I scroll down and I come back, the recyclerview ignores the change I made in switch.
  all the recyclerview will reset.</p>
  
  <p>I want to keep any change in the recyclerview during scroll.</p>
  
  <p>here is my Adapter </p>
  
  <pre><code>public class LightAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;{
  
  
      private List&lt;Light&gt; mList;
      private LightItemClickListener mListener;
      private MainActivity mMainActivity;
  
      public LightAdapter(List&lt;Light&gt; mList, LightItemClickListener mListener, MainActivity mMainActivity) {
          this.mList = mList;
          this.mListener = mListener;
          this.mMainActivity = mMainActivity;
  
      }
  
      @Override
      public LightViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_item, parent, false);
          return new LightViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
          Light light = mList.get(position);
          ((LightViewHolder)holder).getmSwitch().setChecked(light.isLightIsActivated());
          ((LightViewHolder)holder).getmSeekBar().setProgress(light.getLightingValue());
          if(light.isLightIsActivated())
          {
              ((LightViewHolder)holder).getmSwitchOnTextView().setVisibility(View.VISIBLE);
              ((LightViewHolder)holder).getmSwitchOffTextView().setVisibility(View.GONE);
          } else
          {
              ((LightViewHolder)holder).getmSwitchOnTextView().setVisibility(View.GONE);
              ((LightViewHolder)holder).getmSwitchOffTextView().setVisibility(View.VISIBLE);
          }
  
          ((LightViewHolder)holder).getmLightNameTextView().setText(light.getLightName());
          ((LightViewHolder)holder).populateItemView(light, mListener,mMainActivity);
  
  
  
      }
  
  
      @Override
      public int getItemCount() {
          return mList.size();
      }
  
      public void add(List&lt;Light&gt; list) {
          mList.clear();
          mList.addAll(list);
          notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>and my ViewHolder </p>
  
  <pre><code>public class LightViewHolder extends RecyclerView.ViewHolder {
  
      private Context mContext;
  
      private SeekBar mSeekBar;
  
      private Switch mSwitch;
      private TextView mSwitchOffTextView;
      private TextView mSwitchOnTextView;
  
      private TextView mLightNameTextView;
  
      public LightViewHolder(View itemView) {
          super(itemView);
          mSeekBar = itemView.findViewById(R.id.seekBar1);
          mSwitch = itemView.findViewById(R.id.switch1);
          mSwitchOffTextView = itemView.findViewById(R.id.switch_off_textview);
          mSwitchOnTextView = itemView.findViewById(R.id.switch_on_textview);
          mLightNameTextView = itemView.findViewById(R.id.light_name_text_view);
  
      }
  
      public void populateItemView(final Light lightData, final LightItemClickListener onLightClickListener, MainActivity mMainActivity) {
          mContext =mMainActivity.getApplicationContext();
  
          switchClick(lightData,onLightClickListener);
          seekBarChangeValue(lightData,onLightClickListener);
      }
      public SeekBar getmSeekBar() {
          return mSeekBar;
      }
      public TextView getmSwitchOnTextView() {
          return mSwitchOnTextView;
      }
  
      public TextView getmSwitchOffTextView() {
          return mSwitchOffTextView;
      }
  
      public TextView getmLightNameTextView() {
          return mLightNameTextView;
      }
      public Switch getmSwitch() {
          return mSwitch;
      }
  
      public void switchClick(final Light light, final LightItemClickListener onLightClickListener) {
          mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  if(mSwitch.isChecked())
                  {
  
                      mSwitchOffTextView.setVisibility(View.GONE);
                      mSwitchOnTextView.setVisibility(View.VISIBLE);
  
  
                  } else {
                      mSwitchOnTextView.setVisibility(View.GONE);
                      mSwitchOffTextView.setVisibility(View.VISIBLE);
  
                  }
  
                  onLightClickListener.onSwitchClickListener(light);
              }
          });
  
      }
  
      private void seekBarChangeValue(final Light light, final LightItemClickListener onLightClickListener) {
  
  
          mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
              @Override
              public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                  Log.d("test","changed");
              }
  
              @Override
              public void onStartTrackingTouch(SeekBar seekBar) {
                  Log.d("test","start");
              }
  
              @Override
              public void onStopTrackingTouch(SeekBar seekBar) {
  
  
                  onLightClickListener.onSeekBarStopListener(light);
              }
          });
  
      }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>