简体   繁体   中英

If the List is Empty in the RecyclerView, I want to Display Toast with Empty Message

I'm getting the default card in recyclerView for the concept of pagination, as my code in the Fragment is as follows:

private void onResponse(String response) {


   NewEnquiryPagination newEnquiries = new Gson().fromJson(response, new TypeToken<NewEnquiryPagination>() {
    }.getType());

    Log.i("@sandy,", "newEnquiriesFirstPage: " + newEnquiries);

    if (listOfEnquiries !=null) {

        adapter.addAll(newEnquiries.getContent());

        if (currentPage <= TOTAL_PAGES) adapter.addLoadingFooter();
        else isLastPage = true;
    }
}



private void onResponseNextPage(String response) {

    adapter.removeLoadingFooter();
    isLoading = false;
    NewEnquiryPagination newEnquiries = new Gson().fromJson(response, new TypeToken<NewEnquiryPagination>() {
    }.getType());
    if (listOfEnquiries != null ) {

        adapter.addAll(newEnquiries.getContent());

        if (currentPage != TOTAL_PAGES) adapter.addLoadingFooter();
        else isLastPage = true;
    }
}

I'm getting the list from the content as empty but in default i'm getting the card set and also on SwipeRefresh the card is increasing by one.... the problem is in loadFirstPage(); method, if the list is empty i just want to display the snackbar as empty and on SwipeRefresh i just want to refresh the list.

Please help me

Just Put this If Condition to check the Null and Size of the list,

 if (newEnquiries.getContent() != null && newEnquiries.getContent().size() > 0) {
        Log.i("@sss","OnRes");
        adapter.addAll(newEnquiries.getContent());
        if (currentPage <= TOTAL_PAGES) adapter.addLoadingFooter();
        else isLastPage = true;
    } else {
      //Your else condition
    }

Hope so it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM