我正在尝试将多个数据传递给单个setText,用逗号分隔。我能够得到结果并将其显示在日志中,但我不知道如何将它们放在一起。
示例:喜剧,冒险
if (response.isSuccessful()) {
Data data = response.body();
for (Movie movie : data.getData()) {//iterate through all movies
Attributes attributes = movie.getAttributes();
Log.i("INFO", attributes.getName());
textGeners.setText(attributes.getName());
}
}
使用
textGeners.append(attributes.getName()+", ");
或使用
if (response.isSuccessful()) {
Data data = response.body();
StringBuilder attrs = new StringBuilder();
for (Movie Movie : data.getData()) {
Attributes attributes = movie.getAttributes();
Log.i("INFO", attributes.getName());
attrs.append(attributes.getName() + ", ");
}
textGeners.setText(attrs.toString());
}
if (response.isSuccessful()) {
Data data = response.body();
String s = ""; int i = 0;
for (Movie movie : data.getData()) {//iterate through all movies
Attributes attributes = movie.getAttributes();
if( i < 1)
{
s += attributes.getName();
}else{
s+= ","+attributes.getName(); // this will ignore the last ','
}
Log.i("INFO", attributes.getName()); i++;
}
textGeners.setText(s);
}