2
我有一個自定義的ArrayAdapter,並且在某些時候我調用super.sort(new MyComparatorB(orderType, context));
,但在MyComparatorB中實現的比較(DeviceB lhs,DeviceB rhs)方法永遠不會被調用,並且下一條指令正常執行。問題是什麼?排序列表視圖時未調用比較方法
UPDATE
MyComparatorB
public class MyComparatorB implements Comparator<DeviceB> {
private String orderType;
private Context cont;
public MyComparatorB(String type, Context cont) {
this.orderType = type;
this.cont = cont;
}
public int compare(DeviceB lhs, DeviceB rhs) {
int res = 0;
if (orderType.equals(cont.getString(R.string.alpha_text))) {
res = (lhs.getName()).compareTo(rhs.getName());
}
else if (orderType.equals(cont.getString(R.string.lastAct_text))) {
res = (rhs.getTime().getTime()).compareTo(lhs.getTime().getTime());
}
return res;
}
}
DeviceBAdapter
public class DeviceBAdapter extends ArrayAdapter<DeviceB> implements Filterable {
private Context context;
private ArrayList<DeviceB> allDev;
private ArrayList<DeviceB> dev;
//...
public DeviceBAdapter(Context context, BliveAPI blapi) {
super(context, R.layout.sensor_row_state_list);
this.context = context;
this.bliveapi = blapi;
this.allDev = allDevToArrayList();
this.dev = new ArrayList<DeviceB>(allDev);
notifyDataSetChanged();
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
public void sort(String s) {
super.sort(new MyComparatorB(s,context));
notifyDataSetChanged();
}
//...
}
MyActivity
//...
myDevAdapter.sort(getString(R.string.alpha_text));
//...
你能不能給我們更多的信息。我希望看到一些代碼。 – 2012-03-29 14:31:18
@Sachin,添加了一些代碼... – amp 2012-03-29 14:48:45