仅将姓氏名称而不是所有唯一类别添加到TextView中
Set<String> uniqueCategories; // global
......
uniqueCategories = new TreeSet<>();
for(Checkout c : checkOutArrayList) {
uniqueCategories.add(c.getCategory());
}
for (String strGlobalCategory : uniqueCategories) {
System.out.println("Unique:"+strGlobalCategory);
textVisible.setText(strGlobalCategory); // getting name of last Category only
}
当我在每个循环中使用
textVisitCharges.setText(strGlobalCategory);
时,无法将strGlobalCategory
解析为变量 最佳答案
您应该将所有类别附加到单个String
并将结果分配给TextView
:
StrinbBuilder text = new StringBuilder();
boolean first = true;
for (String strGlobalCategory : uniqueCategories) {
if (!first) {
text.append(", ");
}
first = false;
text.append (strGlobalCategory);
}
textVisible.setText(text.toSTring());