2017-12-17 51 views
0

私はtextviewsにいくつかのjsonデータを表示しようとしています。私の "getTitle" getterメソッドは正常に動作し、データはtextviewウィジェットに表示されます。しかし、私は "getDescription"ゲッターメソッドを渡す必要があります、それは提案のために来ていません。 私はこれについて少し助けてくれるでしょうし、もし誰かが私に正しい方向を向けることができる正しい方法をやっていないのであれば、本当に助けてくれるでしょう。jsonをテキストビューに表示するにはどうすればよいですか?

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; 
} 
+2

あなたのtextviewはどこですか? –

答えて

0

以下試してみてください、あなたはレスポンスのボディは、あなたが定義したデータやレスポンスオブジェクトを保持する応答

campaignName.setText(response.body().getDescription()) 
+0

完璧に作業しました。また、私の「getTitle」ゲッターメソッドで表示されていたデータが実際に正しいものではなかったこともわかりました。だから尊敬する –

0

上のメソッドを呼び出しています。応答オブジェクトのgetterメソッドまたはsetterメソッドを呼び出すには、response.body()。getDescription()、response.body()。getCreated()などの応答の本体を使用する必要があります。 TextViewで説明を表示するには、これを試してみてください

campaignDesc.setText(response.body().getDescription())

関連する問題