Last active
February 1, 2017 12:30
-
-
Save madhu314/ecb7e21bc38c3c68e2469eaca9c01aa7 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
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