B
B
bot82016-07-04 18:29:11
Android
bot8, 2016-07-04 18:29:11

VKontakte dialogues are loaded every other time. What is the problem?

Help deal with the problem!
At startup, the dialogs are loaded every other time. What could be the problem?

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;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question