0
サーバーサイドからRecyclerViewにデータを取得しますが、コードは常に最後のテキストをTextViewに設定します。私はとても混乱しています。手伝って頂けますか?ありがとう。私は以下のコードを共有しています。ループは常にAndroidのTextViewに最後のデータを設定します
private void bindDatas() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(NewsService.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
NewsService newsService = retrofit.create(NewsService.class);
final Call<NewsCatalog> requestCatalog = newsService.newsCatalog();
requestCatalog.enqueue(new Callback<NewsCatalog>() {
@Override
public void onResponse(Call<NewsCatalog> call, Response<NewsCatalog> response) {
NewsCatalog catalog = response.body();
SubNodes subNodes = new SubNodes();
mainNodes = new MainNodes();
for (int i = 0; i < catalog.nodes.size(); i++) {
mainNodes = catalog.nodes.get(i);
Log.i(TAG, "" + mainNodes.node.body);
subNodes.setBody(mainNodes.node.body);
subNodesList.add(subNodes);
adapter.notifyDataSetChanged();
}
}
@Override
public void onFailure(Call<NewsCatalog> call, Throwable t) {
Log.e(TAG, "Error: " + t.getMessage());
}
});
}
はあなたにそれが働いた非常@sakiMに感謝:) – nuhkoca