У меня есть настраиваемый ArrayAdapter, и в какой-то момент я вызываю super.sort(new MyComparatorB(orderType, context));
, но метод сравнения (DeviceB lhs, DeviceB rhs), реализованный в MyComparatorB, никогда не вызывается, а следующая инструкция выполняется нормально. Что может быть проблемой?Метод сравнения не вызывается при сортировке списка.
ОБНОВЛЕНИЕ
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));
//...
Можете ли вы дать нам больше информации , Я бы хотел увидеть какой-нибудь код, пожалуйста. –
@Sachin, добавлен некоторый код ... – amp