我能够按升序排序,但无法按降序排序。这是我使用过的代码。
public class RssItemComparator implements Comparator<RssItem> {
DateFormat simpleDateFormat = new SimpleDateFormat("E, dd MMM yyyy hh:mm");
Date date1, date2;
@Override
public int compare(RssItem rssItem1, RssItem rssItem2) {
try {
date1 = simpleDateFormat.parse(rssItem1.getPubDate());
date2 = simpleDateFormat.parse(rssItem2.getPubDate());
} catch (ParseException e) {
e.printStackTrace();
}
return date2.compareTo(date1);
}
}
以不寻常的方式创建了这种排序.Eg:
答案 0 :(得分:0)
尝试在活动显示时创建电影实例,并在更改为新活动时将其删除。这应该可以解决内存不足的问题。
活动生命周期 - https://developer.android.com/images/activity_lifecycle.png
在活动开始之前显示它运行onResume() - 这可能是您创建和准备要显示的电影的地方,
然后在它消失之前因为一个新的活动在它上面或用户关闭一个应用程序,它运行onPause() - 这可能是你删除电影以避免内存不足的问题
// import declarations ommited
public class DetailActivity extends Activity {
Movie aMovie;
// other variables ommited
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// other logics ommited
}
// this will run everytime an instance of DetailActivity is on a screen
@Override
public void onResume() {
// create and instance of aMovie and show it
// this will ensure the same movie of this instance of DetailActivity will show everytime when it's showing on screen
}
// this will run everytime an instance of DetailActivity is closed or, another instance of an activity is pushed on top of it
@Override
public void onPause() {
// remove, delete or free resource of an instance of aMovie
// so this will help about not running out of memory since we
}
// other methods ommited
}