1
我正在使用Sortable TableView库来创建具有排序功能的表结构。图书馆是如下:如何动态排序可排序tableview库中的列?
https://github.com/ISchwarz23/SortableTableView
我有在我得到头和表体JSON响应。在表中,我填充头和体:
String[] myarray = new String[goalData.getTableheaderList().size()];
for (int i = 0; i < goalData.getTableheaderList().size(); i++) {
myarray[i] = goalData.getTableheaderList().get(i).getName();
if (goalData.getTableheaderList().get(i).isSort()) {
int index = GoalsUtils.getIndex(goalData.getTableBodyList().get(0),
goalData.getTableheaderList().get(i).getKey());
setColumnComparator(i, TableComparator.getBodyComparator(index));
}
}
正如你可以看到我已经使用阵列来显示标题和正文也显示在相同的方式不同的代码。此外,我在循环中使用了Column Comparator来根据数据对列进行排序。这是我的表比较类:
public final class TableComparator {
private static int headerIndex;
private TableComparator() {
//no instance
}
public static Comparator<List<TableBody>> getBodyComparator(int index) {
headerIndex = index;
return new BodyComparator();
}
private static class BodyComparator implements Comparator<List<TableBody>> {
@Override
public int compare(final List<TableBody> body1, final List<TableBody> body2) {
return body1.get(headerIndex).getValue().compareTo(body2.get(headerIndex).getValue());
}
}
}
现在的问题是,我总是得到headerIndex固定在上面的代码。我的问题是如何动态获取它。有没有人知道如何检测这个库中的标题点击,或者我们如何在标题列点击时获得不同的headerIndex?任何帮助将不胜感激。