我正在尝试向文本视图显示一些JSON数据。我的" getTitle" getter方法正常工作,并且数据显示在文本视图小部件中。但是,当我应该通过" 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;
}
尝试下面,您正在呼叫响应
上调用方法campaignName.setText(response.body().getDescription())
响应的主体将保留您定义的数据或响应对象。因此,要调用响应对象的任何getter或setter方法,您必须使用响应的主体,例如响应。Body()。getDescription(),响应。Body.body()。getCreated()。要在文本视图中显示描述,请尝试以下
campaignDesc.setText(response.body().getDescription())