如何在回收站视图中填充阵列列表

时间:2019-05-15 04:01:29

标签: java android android-recyclerview

我正在数组列表中工作,我正在从api获取响应,我希望将其填充到回收站视图中

我创建了一个数组列表来存储api响应中的数据

public void getInviteContacts(int currentPage) {


    RestClient.getInstance(context).get().getContactDetails(token, 1, 0, 16).enqueue(new Callback<ContactsResponse>() {
        @Override
        public void onResponse(Call<ContactsResponse> call, Response<ContactsResponse> response) {
            Log.d("contact details", "Contact");

            if (response.body() != null && response.body().getData() != null)
                contactsInviteDataList = response.body().getData();
                total = response.body().getCount();

            //currentPageCal(response);

            adapterInviteContact.setInviteList(contactsInviteDataList);
            adapterInviteContact.setListCount(total);
            listInviteUserContacts.setAdapter(adapterInviteContact);

            SharedPreferenceManager.instance.storeStringInPreference(Constants.MOBILE_NAME,
                    Constants.EMPTY_STRING);

        }

        @Override
        public void onFailure(Call<ContactsResponse> call, Throwable t) {

            Log.d("Failure", "Contact");

        }
    });

}
private void handleListClickAndScroll() {
    WrapContentLayoutManager layoutManager = new WrapContentLayoutManager(context);
    listInviteUserContacts = findViewById(R.id.view_list_contacts);
    statusView = findViewById(R.id.status_view);
    adapterInviteUserContact = new ContactsAdapter(context, this,this);
    contactInvite = new ArrayList<>();

    statusView.setText(getString(R.string.msg_no_results));

    contactInvite = CfDatabaseManager.ROSTER.getLocalRosters(LibConstants.TYPE_CHAT);
    showInviteUserContacts(contactInvite);
    adapterInviteUserContact.setContactList(contactsInviteDataList);
    listInviteUserContacts.setLayoutManager(layoutManager);
    listInviteUserContacts.setEmptyView(statusView);
    listInviteUserContacts.setAdapter(adapterInviteUserContact);

    ItemClickSupport.addTo(listInviteUserContacts).setOnItemClickListener((recyclerView,
                                                                           position, v) -> {
        email = Utils.returnEmptyStringIfNull(contactInvite.get(position).getVcard().getEmail
                ());
        mobileNumber = contactInvite.get(position).getVcard().getUserInfo().getMobileNo();
        commonAlertDialog.showListDialog(
                getString(R.string.title_invite_friend),
                getResources().getStringArray(R.array.array_invite_contact));
    });
}

在onCreate中调用的两个方法

实际结果是空指针异常,预期结果是在回收器视图中填充该视图

0 个答案:

没有答案