![](/img/trans.png)
[英]Android, Best way to populate Endless List View's data with Retrofit?
[英]What's the best way to populate List<Object>?
List<Branch>
有100個Branch對象,並且已經設置了branchId(001到100)。我想使用List<Branch>
通過iReport進行報告。
但是現在我的數據全部在另一個List List<Temp>
並且該數據在List<Temp>
重復。
branchId firstName lastName type number
-------------------------------------------------------------
005 Amy Lee home 1234567
005 Amy Lee office 9999999
005 Amy Lee cellphone 1111111
005 John Lin home 1231231
067 Louis Tsai home 0809097
....
我的問題如下:
我需要使用List<Temp>
轉換為List<Branch>
,如果branchId在List<Branch>
不匹配,只需將List<User>
設置為null。 我能怎么做?
public class Temp{
private String branchId;
private String firstName;
private String lastName;
private String type;
private String number;
//getter and setter here
}
分支豆
public class Branch {
private String branchId;
private List<User> user;
//getter and setter here
}
用戶Bean
public class User {
private String firstName;
private String lastName;
private List<Phone> phones;
//getter and setter here
}
電話豆
public class Phone {
private String type;
private String number;
//getter and setter here
}
非常感謝。
-----------更新----------------
如您所見,下面是我需要的樣子:
在branchId 005下排序的是Amy Lee和John Lin,不同的branchId 067將顯示在不同的頁面中。使用相同的branchId,例如005 Amy Lee,她下面有3種數字。 現在,報告需要檢索List<Branch>
。 這就是為什么我需要循環List<Temp>
並設置List<Branch>
。 有什么辦法可以做到嗎?
005
-----------------------------------
Amy Lee home 1234567
office 9999999
cellphone 1111111
John Lin home 1231231
下一頁
067
-----------------------------------
Louis Tsai home 0809097
如果我是您,我將用地圖替換這些列表,用法將是這樣的。
List<temp> t;
for (temp t : tempList) {
if ((Branch b = branchMap.get(t.getBranchID)) != null) {
if ((user u = b.getUsers.get((t.getFirstName() + t.getLastName()) != null) {
user.getPhonse.add(new Phone(t.getPhoneType(), t.getPhoneNumber()))
}
} else {
List<Phone> phonse = new ArrayList<Phone>();
phonse.add(new Phone(t.getPhoneType(), t.getPhoneNumber()));
Map<String,String> users = new hashMap<String,String>();
users.put(t.getFirstName() + t.getLastName(), new user(t.getFirstName(), t.getLastName(), phones);
branchMap.put(t.getBranchID, new Branch(t.getBranchID(), new hashMap<String,String>().put(t.getFirstName() + t.getLastName(), new user(t.getFrstName(), t.getLastName(), new List<Phone>))))))
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.