我已经开发了一个连接到Firebase数据库的Android应用程序。我正在尝试在ListView中显示来自数据库对象的一些记录,但是我不确定如何处理布尔值。我目前有一个GroupVaccinations类,其中包含所有信息的Getter:
public class GroupVaccination {
String vaccinationGroupID;
String vaccinationGroupNumber;
String vaccinationID;
String vaccinationDrug;
String vaccinationAdmin;
String vaccinationDosage;
String vaccinationDate;
String vaccinationNotes;
Boolean allVaccinated;
public GroupVaccination(){
}
public GroupVaccination(String vaccinationGroupID, String vaccinationGroupNumber, String vaccinationID, String vaccinationDrug,
String vaccinationAdmin, String vaccinationDosage, String vaccinationDate, String vaccinationNotes, Boolean allVaccinated){
this.vaccinationGroupID = vaccinationGroupID;
this.vaccinationGroupNumber = vaccinationGroupNumber;
this.vaccinationID = vaccinationID;
this.vaccinationDrug = vaccinationDrug;
this.vaccinationAdmin = vaccinationAdmin;
this.vaccinationDosage = vaccinationDosage;
this.vaccinationDate = vaccinationDate;
this.vaccinationNotes = vaccinationNotes;
this.allVaccinated = allVaccinated;
}
public String getVaccinationGroupID() { return vaccinationGroupID; }
public String getVaccinationGroupNumber() { return vaccinationGroupNumber; }
public String getVaccinationID() { return vaccinationID; }
public String getVaccinationDrug() { return vaccinationDrug; }
public String getVaccinationAdmin() { return vaccinationAdmin;}
public String getVaccinationDosage() {return vaccinationDosage;}
public String getVaccinationDate() {return vaccinationDate; }
public String getVaccinationNotes() {return vaccinationNotes; }
public Boolean getAllVaccinated() {return allVaccinated; }
我正在使用InfoAdapter类来相应地填充ListView:
public class GroupVaccinationInfoAdapter extends ArrayAdapter<GroupVaccination> {
private Activity context;
private List<GroupVaccination> groupVaccinationList;
public GroupVaccinationInfoAdapter(Activity context, List<GroupVaccination>groupVaccinationList){
super(context, R.layout.group_vaccination_list_view,groupVaccinationList);
this.context = context;
this.groupVaccinationList = groupVaccinationList;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listView = inflater.inflate(R.layout.group_vaccination_list_view, null, true);
TextView vaccinationDrug = (TextView)listView.findViewById(R.id.drug);
TextView vaccinationDosage = (TextView)listView.findViewById(R.id.dosage);
TextView vaccinationDate = (TextView)listView.findViewById(R.id.date);
TextView vaccinationAdmin = (TextView)listView.findViewById(R.id.administrator);
TextView vaccinationID = (TextView) listView.findViewById(R.id.groupVaccinationID);
TextView vaccinationGroupNumber = (TextView)listView.findViewById(R.id.groupNumber);
TextView vaccinationNotes = (TextView)listView.findViewById(R.id.notes);
TextView allVaccinatedTrueFalse = (TextView)listView.findViewById(R.id.allVaccinatedTrueFalse);
GroupVaccination groupVaccination = groupVaccinationList.get(position);
vaccinationDrug.setText(groupVaccination.getVaccinationDrug());
vaccinationDosage.setText(groupVaccination.getVaccinationDosage());
vaccinationDate.setText(groupVaccination.getVaccinationDate());
vaccinationID.setText(groupVaccination.getVaccinationID());
vaccinationAdmin.setText(groupVaccination.getVaccinationAdmin());
vaccinationGroupNumber.setText(groupVaccination.getVaccinationGroupNumber());
vaccinationNotes.setText(groupVaccination.getVaccinationNotes());
allVaccinatedTrueFalse.setText(String.valueOf(Boolean groupVaccination.getAllVaccinated));
return listView;
}
当我尝试将allVaccinatedTrueFalse.setText的Boolean
转换为String
时出现错误。我假设这种方式是错误的,所以任何帮助将不胜感激!让我知道是否需要其他信息。谢谢!
答案 0 :(得分:1)
要解决此问题,请更改以下代码行:
allVaccinatedTrueFalse.setText(String.valueOf(Boolean groupVaccination.getAllVaccinated));
到
allVaccinatedTrueFalse.setText(String.valueOf(groupVaccination.getAllVaccinated()));