2

嗨,我正在对来自 web 服务的日期进行排序,即 json,我需要根据创建的日期对其进行排序。正常排序 Collections.sort 不起作用我需要在排序之前格式化日期如何做到这一点

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() 进行排序。从 tthis 函数返回的值

4

1 回答 1

0

那么您想使用 getAssetEventDate() 对列表进行排序吗?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;
            }
        }
}
于 2013-04-06T12:43:12.643 回答