I have a recyclerView full of CardViews that have 2 paramteres (Both of them are Strings), one of those is a title,I would like to have a button to sort them alphabetically base
The easiest way to sort a list is to use java.util.Collections
Collections.sort(categories, new Comparator<Categories>() {
@Override
public int compare(Categories lhs, Categories rhs) {
return lhs.title.compareTo(rhs.title);
}
});
This will compare the title character by character. and will sort your list from a to z.
Don't forget after the modification to notify the list that the data have changed with notifyDataSetChanged()
(from your RecyclerView.Adapter
).