我有一个片段,我将请求发送到服务器。由于我的应用程序中的离线模式,我使用数据库存储对象,然后我将它们设置为recyclerView。
是否有其他(更好)的方法来保存数据而不是 for loop ?
我发布的请求
private void getContacts() {
showProgressDialog();
FactoryAPI.getContacts().getContacts(user.getToken()).enqueue(new Callback<ContactsResponse>() {
@Override
public void onResponse(Call<ContactsResponse> call, Response<ContactsResponse> response) {
if (response.isSuccessful()) {
contactList = response.body().getContactsList();
for (int i = 0; i < contactList.size(); i++) {
ContactORM contact = new ContactORM();
contact.setId(contactList.get(i).getId());
contact.setName(contactList.get(i).getName());
contact.setLastname(contactList.get(i).getLastname());
contact.setEmail(contactList.get(i).getEmail());
contact.setPhoto(contactList.get(i).getPhoto());
contact.save();
databaseList.add(contact);
}
sortList();
progressDialog.dismiss();
setRecyclerView();
}
}