In my Android app, I have a list of a Custom object having the following fields,
var myNotesList: ArrayList<Note>
class Note(
var title: String
var date: String,
var status: String)
Here the status
can be any of the following three values:
Draft, Pending, Completed
Now, I want my list to be ordered in the fashion where Drafts are first and sorted in descending order of date, then Pending sorted with the date then Completed status items.
for example,
{someNoteTitle, draft, 07 Jan 2021},
{someNoteTitle, draft, 06 Jan 2021},
{someNoteTitle, draft, 04 Jan 2021},
{someNoteTitle, Pending, 07 Jan 2021},
{someNoteTitle, Pending, 06 Jan 2021},
{someNoteTitle, Completed, 07 Jan 2021},
{someNoteTitle, Completed, 05 Jan 2021},
{someNoteTitle, Completed, 02 Jan 2021}
I have tried with the sortedWith
and compareBy
but due to the status order requirement is not alphabetical, I am not getting a way to do this with in-built functions, or else I will have to do it in a dirty way with loops.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…