【发布时间】:2013-02-17 01:34:34
【问题描述】:
如何强制数组适配器自行排序。 notifyDataSetChanged 不起作用。我想要做的是将一个项目添加到数组 adpater,然后强制它再次排序。 这是我的适配器:
this.noteListViewAdapter = new NoteListViewAdapter(this.GetActivityContext(), R.layout.list_view_note_item, noteItems);
// sorting
this.noteListViewAdapter.sort(new Comparator<NoteItem>()
{
@Override
public int compare(NoteItem item1, NoteItem item2)
{
// TODO Auto-generated method stub
return item2.CreationDate.compareTo(item1.CreationDate);
};
});
它工作正常。项目已排序。但是当我想添加新项目时,排序不起作用。它甚至没有被调用。 这就是我添加新项目的方式:
this.noteListViewAdapter.add(note);
this.noteListViewAdapter.notifyDataSetChanged();
感谢您的帮助
【问题讨论】:
-
在 add() 之后在 notifyDataSetChanged() 之前再次排序;