I am making gallery app and I want to add sorting to it I can sort item at run time by using Comparator
but problem is whenever I quit app the list came form database again and all the list is unsorted I want to give option in my app to sort by date,size, name etc can you guys help how can i ahcevie this and remmeber user's choice if he next time run the app I have also read about sorted-list please tell me what is solution to my problem or any sample code currently I am doing this like this to sort items
public static final Comparator<MediaFileObject> byName=new Comparator<MediaFileObject>() {
@Override
public int compare(MediaFileObject o1, MediaFileObject o2) {
return o1.getAddedDate().compareTo(o2.getAddedDate());
}
};
and i call this in my fragment
Collections.sort(list,MediaFileObject.byName);
galleryAdapter.notifyDataSetChanged()
this is working fine but i want to remember user sorting choice please someone help what should i do?
can i achieve this by using SortedList
? or any sample code please
You can create a options list like sort by Date, Size, Name etc. Make one of the options as the default option and save to sharedpreference. when a user changes the sorting type make the selected option as the default.
When you read the data from the database, as per the selected sorting option, apply the collection sort. I believe no code snippet require for that.
This help you to sort list, based on Name and Date.