我正在尝试向textviews显示一些json数据。我的“getTitle”getter方法工作正常,数据显示在textview小部件中。但是,当我应该通过“getDescription”getter方法时,它不会出现建议。 我真的很喜欢这方面的一些帮助,或者如果我没有按照正确的方式指出我正确的方向。
call.enqueue(new Callback<Campaign>() {
@Override
public void onResponse(Call<Campaign> call, Response<Campaign> response) {
if (response.isSuccessful()) {
String id = response.body().getId();
campaignName.setText(getTitle());
campaignDesc.setText();
} else {
Toast.makeText(StartSurveyActivity.this, "Error Retrieving Id", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Campaign> call, Throwable t) {
// Log error here if request failed
Log.e(TAG, t.toString());
}
});
}
这是我的java广告系列模型类。另外我认为重要的是要提到我的“getDescription”getter和setter以浅灰色显示,而“getTitle”getter和setter则是金色的颜色。感谢您的帮助。
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public Boolean getDeleted() {
return deleted;
}
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSurveyUrl() {
return surveyUrl;
}
public void setSurveyUrl(String surveyUrl) {
this.surveyUrl = surveyUrl;
}
public Integer getTotalResponseCount() {
return totalResponseCount;
}
public void setTotalResponseCount(Integer totalResponseCount) {
this.totalResponseCount = totalResponseCount;
}
public String getLanguageCode() {
return languageCode;
}
public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getOrganisationLogoUrl() {
return organisationLogoUrl;
}
public void setOrganisationLogoUrl(String organisationLogoUrl) {
this.organisationLogoUrl = organisationLogoUrl;
}
public String getOrganisationName() {
return organisationName;
}
public void setOrganisationName(String organisationName) {
this.organisationName = organisationName;
}
答案 0 :(得分:0)
请尝试以下操作,您正在调用方法
campaignName.setText(response.body().getDescription())
答案 1 :(得分:0)
响应正文将保存您定义的数据或响应对象。因此,要调用响应对象的任何getter或setter方法,必须使用响应的主体,例如response.body()。getDescription(),response.body()。getCreated()。要在TextView中显示说明,请尝试使用
campaignDesc.setText(response.body().getDescription())