Recently, in your project, you need to sort the read data in descending order of time.
The specific steps are as follows:
1. Read the data and deposit it in the list
2. Take the timestamp from the data and convert it from string to date
3. Sort elements in list by date using bubbling sort
The specific code is as follows:
Sort the list in reverse chronological order
@SuppressLint ("SimpleDateFormat")
Private list<testentity> invertorderlist (list<testentity> L) {
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Date D1;
Date D2;
Testentity temp_r = new Testentity ();
Do a bubble sort, big in the top of the array
for (int i=0; I<l.size ()-1; i++) {
for (int j=i+1; j<l.size (); j + +) {
Parseposition pos1 = new Parseposition (0);
Parseposition Pos2 = new Parseposition (0);
D1 = Sdf.parse (L.get (i). GetDate (), POS1);
D2 = Sdf.parse (L.get (j). GetDate (), POS2);
if (D1.before (D2)) {//If the team pre-date, swap order
Temp_r = L.get (i);
L.set (I, L.get (j));
L.set (J, Temp_r);
}
}
}
return L;
}
Sort the list's date elements in Android