Hi guys How would i be able to sort a recyclerview by the data that is within a certain textview which is inside each item inside the recyclerview. I also would love to know
First of all Sort the data using Comparator before setting adapter. using Collections.
import java.util.Collections
like
Collections.sort(categories, new Comparator() {
@Override
public int compare(AnyClasslhs, AnyClassrhs) {
return lhs.label.compareTo(rhs.label);
}
});
In above I sort a lable in AnyClass alphabetically
. And In order to add a header you have to convert the label into charArray and compare it with last item in array. if it is not that then add a header.
Some Helpful links
https://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/
https://github.com/amalChandran/ListviewAlphabetIndexer
Display Namelist In Recyclerview under each letter in alphabetic Order Android