![](/img/trans.png)
[英]how to TextView.setText(List<String>object) like TextView.setText(array[index]) settext from List
[英]How to pass data from an api as array in setText
我试图将多个数据传递给单个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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.