Skip to content

Instantly share code, notes, and snippets.

@madhu314
Last active February 1, 2017 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save madhu314/ecb7e21bc38c3c68e2469eaca9c01aa7 to your computer and use it in GitHub Desktop.
Save madhu314/ecb7e21bc38c3c68e2469eaca9c01aa7 to your computer and use it in GitHub Desktop.
package is.uncommon.playbook.sortedlist.part1;
import android.support.v7.util.SortedList;
import android.support.v7.widget.util.SortedListAdapterCallback;
import android.view.ViewGroup;
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