title: How to update RecyclerView adapter using DiffUtil
body: <p>Im used to create a new Adapter and an new RecycleView every time I needed  to update the alarms that in the RecycleView. unfortunately it just a very expensive "solution". I saw online that I can use DiffUti, but Im not sure how to implement it.
  I created a DiffUtil class:</p>
  
  <pre><code>public class AlarmDiffCallBack extends DiffUtil.Callback{
  private final ArrayList&lt;SingleAlarm&gt; oldList;
  private final  ArrayList&lt;SingleAlarm&gt; newList;
  
  public AlarmDiffCallBack( ArrayList&lt;SingleAlarm&gt; oldList, ArrayList&lt;SingleAlarm&gt; newList) {
      this.oldList = oldList;
      this.newList = newList;
  }
  
  @Override
  public int getOldListSize() {
      return oldList.size();
  }
  
  @Override
  public int getNewListSize() {
      return newList.size();
  }
  
  @Override
  public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
      return oldList.get(oldItemPosition).getAlarmIndex() == newList.get(newItemPosition).getAlarmIndex();
  }
  
  @Override
  public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
      return oldList.get(oldItemPosition).getAlarmIndex() == newList.get(newItemPosition).getAlarmIndex();
  }
  
  @Nullable
  @Override
  public Object getChangePayload(int oldItemPosition, int newItemPosition) {
      // Implement method if you're going to use ItemAnimator
      return super.getChangePayload(oldItemPosition, newItemPosition);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and this is one of the places I want to update the recycleView in(replace the "creatAdapter" with the DiffUtil):</p>
  
  <pre><code> public void add_alarm(final Context context) {
      //creating a new alarm and set the relevant varible to the addAlarm function
      button_add_alarm.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              //the calndar is without the right day, the day is added in the handler(int the loop)
              Calendar calendarForAlarm = timePickerToCalendar(alarmTimePicker);
              alarmsList = alarmHandler.add_alarm(context, checkBoxes, alarmMessage, alarmsList, alarm_manager, calendarForAlarm, repeatAlarm);
              alarmsList=alarmHandler.sortAlarms(alarmsList);
              creatAdapt();
          }
      });
  }
  </code></pre>
  
  <p>I just cant figure out how to use this class to update my Adapter. Im pretty new to android and programming in general, hope this quotation is OK. Thanks!</p>