我有以下 ListView 代码:
private class CollegeItem {
private double gpa;
private int act;
private int sat;
private String name;
private String location;
private double score;
private boolean match;
private double scoreDistance;
private boolean uaero, uagri, ubio, uchem, ucivil, ucomp, uelec, uphys, uenvi, uindus, umate, umech;
public CollegeItem(double gpa, int act, int sat, String name, String location, boolean uaero, boolean uagri, boolean ubio, boolean uchem,
boolean ucivil, boolean ucomp, boolean uelec, boolean uphys, boolean uenvi, boolean uindus, boolean umate, boolean umech){
this.gpa = gpa;
this.act = act;
this.sat = sat;
this.name = name;
this.location = location;
this.uaero = uaero;
this.uagri = uagri;
this.ubio = ubio;
this.uchem = uchem;
this.ucivil = ucivil;
this.ucomp = ucomp;
this.uelec = uelec;
this.uphys = uphys;
this.uenvi = uenvi;
this.uindus = uindus;
this.umate = umate;
this.umech = umech;
if(act/36.0>sat/2400.0){
this.score = 0.6*gpa*25.0+0.4*(act/36.0)*100.0;
}else{
this.score = 0.6*gpa*25.0+0.4*(sat/2400.0)*100.0;
}
scoreDistance = Math.abs(this.score-MainActivity.scoreDouble)/MainActivity.scoreDouble;
if(uagri&&ListOfMajors.agricultural||uchem&&ListOfMajors.chem||uaero&&ListOfMajors.aerospace||ubio&&ListOfMajors.biomed||ucivil&&ListOfMajors.civil
||ucomp&&ListOfMajors.computer||uelec&&ListOfMajors.electrical||uphys&&ListOfMajors.physics||uenvi&&ListOfMajors.environment||uindus&&ListOfMajors.industrial
||umate&&ListOfMajors.materials||umech&&ListOfMajors.mechanical){
scoreDistance--;
}else{
scoreDistance = Math.abs(this.score-MainActivity.scoreDouble)/MainActivity.scoreDouble;
}
}
ArrayList<CollegeItem> collegeLists=new ArrayList<CollegeItem>();
ArrayList<String> nameList = new ArrayList<String>();
Comparator<CollegeItem> compare = new Comparator<CollegeItem>(){
public int compare(CollegeItem a, CollegeItem b){
return Double.compare(a.getScoreDistance(), b.getScoreDistance());
}
};
Collections.sort(collegeLists, compare);
for(CollegeItem collegeList : collegeLists){
nameList.add(collegeList.getName());
}
setListAdapter(new ArrayAdapter<String>(CollegeList.this, android.R.layout.simple_list_item_1, nameList));
截至目前,ListView 的顺序是字段变量 scoreDistance 的升序。它通过比较器以这种方式排序。List 的实际内容是字段变量名。我现在想将字段变量位置添加为每个名称的子项。它仍然应该以相同的方式排序。我已经查看了有关添加子项的多个问题,但仍然不确定如何执行此操作。我应该怎么办?