我有一个列表视图连接到自定义阵列适配器。这份清单显示通过改变DataSet中的TCP连接接收到的信息......排序列表视图与阵列适配器
我可以列表视图与sort (Comparator<? super T> comparator)
排序,但是当这些数据改变时,列表视图中没有更多的分类......
每次dataSet被更改时我都可以使用sort()
,但我认为这不是最好的选择...
我该怎么做?有什么建议么?
编辑
我有落实解决的问题提出了...
MyComparatorB.java
public class MyComparatorB implements Comparator<DeviceB> {
private byte orderType;
public MyComparatorB(byte type) {
this.orderType = type;
}
public int compare(DeviceB lhs, DeviceB rhs) {
int res = 0;
if (orderType == SortType.ALPHA) {
res = (lhs.getName()).compareTo(rhs.getName());
}
else if (orderType == SortType.LAST_ACT) {
res = (rhs.getTime().getTime()).compareTo(lhs.getTime().getTime());
}
return res;
}
}
摘录我customArrayAdapter.java的
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
//-----------Order the content of the arrayAdapter------------//
public void sort(byte sortType) {
super.sort(new MyComparatorB(sortType));
notifyDataSetChanged();
}
在我MyActivity.java
myDevAdapter.sort(SortType.ALPHA);
当我调试,该方法super.sort(new MyComparatorB(sortType));
被称为和MyComparatorB的构造函数被调用了。但方法compare(DeviceB lhs, DeviceB rhs)
永远不会被调用,我的arrayList不排序... 我做错了什么?
为什么你不使用ArrayList并对数组和列进行排序! – Behnam 2012-03-28 11:28:22
我想你应该排序你的数组,并调用adapter.notifyDataSetChanged() – 2012-03-28 11:29:31
@amp:什么是SortType在这里? – YuDroid 2012-12-11 05:43:40