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:
The List is sorted in reverse chronological order @suppresslint ("SimpleDateFormat") Private list<testentity> invertorderlist (list< Testentity> L) {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");D ate d1;date D2; Testentity temp_r = new testentity ();//Make a bubble sort, large in the array of the top 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 front of the team before date, the order of exchange Temp_r = L.get (i); L.set (I, L.get (j)); L.set (J, Temp_r);}} return L;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Sort dates in Android