Помогите разобраться с проблемой!
При запуске диалоги загружаются через раз. В чем может быть проблема?
public class FragmentOnlineDialog extends Fragment {
private RecyclerView mRecyclerView;
private DialogsAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list_dialogs, container, false);
mRecyclerView =(RecyclerView) view.findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
UpdateUI();
return view;
}
private class DialogHolder extends RecyclerView.ViewHolder {
public TextView mTextView;
public DialogHolder(View view) {
super(view);
mTextView = (TextView) view;
}
}
public class DialogsAdapter extends RecyclerView.Adapter<DialogHolder> {
List<Dialog> dialogs;
@Override
public DialogHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, parent, false );
return new DialogHolder(v);
}
@Override
public void onBindViewHolder(DialogHolder holder, int position) {
Dialog dialog = dialogs.get(position);
holder.mTextView.setText(dialog.getTitleDialog());
}
@Override
public int getItemCount() {
return dialogs.size();
}
public DialogsAdapter(List<Dialog> dialogs) {
this.dialogs = dialogs;
}
}
private void UpdateUI() {
List<Dialog> dialogs = getDialogs();
adapter = new DialogsAdapter(dialogs);
mRecyclerView.setAdapter(adapter);
}
private List<Dialog> getDialogs() {
VKRequest request = VKApi.messages().getDialogs(VKParameters.from(VKApiConst.COUNT,
20));
final List<Dialog> dialogs = new ArrayList<>();
request.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
VKApiGetDialogResponse getMessagesResponse = (VKApiGetDialogResponse) response.parsedModel;
VKList<VKApiDialog> mDialogs = getMessagesResponse.items;
for (VKApiDialog d : mDialogs) {
Dialog d1 = new Dialog(d.message.body);
dialogs.add(d1);
}
}
});
return dialogs;
}
}