0
我實現我的CLAS新聞可比,這樣我可以通過publishDate排序實現可比不工作在Android
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class News implements Comparable<News>{
private String title;
private String description;
private String link;
private String guid;
private String pubDate;
private Date date;
private String author;
private String image;
private String category;
private String feedIconLink;
@Override
public int compareTo(News anotherNews) {
long compareDateInMilisecconds = ((News) anotherNews).getDateInMilliseconds();
long result = compareDateInMilisecconds - this.getDateInMilliseconds();
int finalResult = (int) result;
return finalResult;
}
代碼編譯和運行,它thows沒有錯誤安排新聞的數組,但它確實實際上並沒有改變陣列上對象的順序。
@Override
protected void onPostExecute(List<News> input) {
for (News aNews : input){
Log.v("Before", aNews.getFeedIconLink());
}
Arrays.sort(input.toArray());
for (News aNews : input){
Log.v("After", aNews.getFeedIconLink());
}
this.listener.finish(input);
}
I Log.v排序前後沒有變化,即使在調試時它通過整個Array的整個CompareTo方法運行。
有什麼我做錯了嗎?
工作完美,謝謝!解決了 –