亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android實(shí)現(xiàn)數(shù)據(jù)按照時(shí)間排序

 更新時(shí)間:2018年09月24日 09:45:16   作者:隔壁小王66  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)數(shù)據(jù)按照時(shí)間排序的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

經(jīng)常遇見一個(gè)列表,兩個(gè)接口的情況,兩個(gè)接口屬于兩個(gè)不同的表數(shù)據(jù),那么數(shù)據(jù)拼接回來之后,并不是按照時(shí)間排序的,看起來就相當(dāng)混亂,所以記錄一下如何對數(shù)據(jù)按照時(shí)間排序。

步驟一:

格式化日期

public static Date stringToDate(String dateString) {
    ParsePosition position = new ParsePosition(0);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date dateValue = simpleDateFormat.parse(dateString, position);
    return dateValue;
  }

步驟二:

對拼接的列表進(jìn)行排序

private void sortData(ArrayList<CourseModel> mList) {
    Collections.sort(mList, new Comparator<CourseModel>() {
      /**
       *
       * @param lhs
       * @param rhs
       * @return an integer < 0 if lhs is less than rhs, 0 if they are
       *     equal, and > 0 if lhs is greater than rhs,比較數(shù)據(jù)大小時(shí),這里比的是時(shí)間
       */
      @Override
      public int compare(CourseModel lhs, CourseModel rhs) {
        Date date1 = DateUtil.stringToDate(lhs.getCREATE_TIME());
        Date date2 = DateUtil.stringToDate(rhs.getCREATE_TIME());
        // 對日期字段進(jìn)行升序,如果欲降序可采用after方法
        if (date1.before(date2)) {
          return 1;
        }
        return -1;
      }
    });
    adapter.replaceAll(mList);
  }

直接調(diào)用這個(gè)方法,數(shù)據(jù)類型改造一下即可。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論