Skip to content

Instantly share code, notes, and snippets.

@pratul
Forked from madhu314/SortedListAdapter.java
Last active February 1, 2017 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pratul/1778704bb87d557cb0b1cffc191c74bb to your computer and use it in GitHub Desktop.
Save pratul/1778704bb87d557cb0b1cffc191c74bb to your computer and use it in GitHub Desktop.
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