我从json中的服务器获取数据
我正在使用自定义适配器并存储在recyclerview上显示此数据
我正在使用Getter Setter类来获取和设置值 这是我的Getter Setter等级
public class UserData {
String email,firstName;
List<String> companies;
public UserData(String email, String firstName, List<String> companies) {
this.email = email;
this.firstName = firstName;
this.companies = companies;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public List<String> getCompanies() {
return companies;
}
public void setCompanies(List<String> companies) {
this.companies = companies;
}
}
通过使用适配器类,我能够显示电子邮件和firstName,但无法从公司获取数据 获取数据的代码
final UserData rowItem = rowItems.get(position);
holder.tvName.setText(rowItem.getfirstName());
holder.tvEmail.setText(rowItem.getemail());
我想显示公司名单
holder.tvCompanies.setText(strCompaniesName); 我用它来获取用户的公司名称
strCompaniesName = "";
for (int i = 0; i < rowItem.getCompanies().size(); i++) {
Log.i("Value of element " + i, rowItem.getCompanies().get(i));
if (i == 0)
strCompaniesName = rowItem.getCompanies().get(i);
else
strCompaniesName = strCompaniesName + ", \n " + rowItem.getCompanies().get(i);
}