-
-
Save pratul/1778704bb87d557cb0b1cffc191c74bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SortedListAdapter extends IntegerListAdapter { | |
private SortedList<Integer> sortedList; | |
public SortedListAdapter() { | |
this.sortedList = new SortedList<>(Integer.class, new SortedListAdapterCallback<Integer>(this) { | |
@Override public int compare(Integer item1, Integer item2) { | |
return item1.compareTo(item2); | |
} | |
@Override public boolean areContentsTheSame(Integer oldItem, Integer newItem) { | |
return oldItem.equals(newItem); | |
} | |
@Override public boolean areItemsTheSame(Integer item1, Integer item2) { | |
return item1.intValue() == item2.intValue(); | |
} | |
}); | |
; | |
} | |
@Override protected void addInteger(Integer integer) { | |
sortedList.add(integer); | |
} | |
@Override protected void removeInteger(Integer integer) { | |
sortedList.remove(integer); | |
} | |
@Override public IntegerListItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
return IntegerListItemViewHolder.create(parent); | |
} | |
@Override public void onBindViewHolder(IntegerListItemViewHolder holder, int position) { | |
holder.bindTo(sortedList.get(position)); | |
} | |
@Override public int getItemCount() { | |
return sortedList.size(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment