2013-04-06 58 views
2

您好我排序的日期从web服务即json和我需要排序基于创建date.normal排序Collections.sort不工作我需要格式日前排序如何做到这一点在android中从日期排序列表中的日期不是从db

CommunicationEngine.post(getApplicationContext(), "sports", 
        mylibraryRequest, new AsyncHttpResponseHandler() { 
com.loopj.android.http.AsyncHttpResponseHandler#onStart() 

    com.loopj.android.http.AsyncHttpResponseHandler#onSuccess(java.lang.String) 

         @Override 

ObjectMapper sportsMapper = new ObjectMapper();## Heading ##try { 
           SportsResponse sportsResponse = sportsMapper.readValue(sportsResponseASString,SportsResponse.class); 

if (null != sportsResponse) { 
List<Assets> assets = sportsResponse.getAssets(); 
(Assets asset : assets) { 
//sort list 
sort_sportList.add(asset.getTitle() 
               .trim()); 
             if(asset.getSportType() != null){ 
              sort_sport.add(asset.getSportType().trim());          }                   EGLibContent eglibitem = new EGLibContent(
                            .getAssetEventDate(), 

             adapter.getKey("Contents"); 
             adapter.addeglibcontent(eglibitem,ListView); 

我通过排序collections.sort使用的标题通常()

我想排序getAssetEventDate()。从这个函数返回的值

回答

0

所以你想使用getAssetEventDate()对List进行排序? getAssetEventDate返回一个数字?

Collection.sort(assets, new Comparator<Asset>() { 

     @Override 
     public int compare(Asset lhs, Asset rhs) { 
      if (lhs.getAssetEventDate() < rhs.getAssetEventDate() { 
       return -1; 
      } else if (lhs.getAssetEventDate() > rhs.getAssetEventDate() { 
       return 1; 
      } else { 
       return 0; 
      } 
     } 
} 
+0

谢谢Klaasvaak ... – 2013-08-05 09:23:48