jeudi 15 février 2018

filter recyclerview by two indices

I want to filter a recyclerview by two indices:

Category and Classe,

using checkbox, i can't make the exact combinations to filter without error.

public void getFilteredNews(List filters, @NonNull LoadNewsCallback callback) {

    List<NewsItem> newsItemList = new ArrayList<>();
    getCursor(newsItemList);

    List<NewsItem> filtredItemList = new ArrayList<>();

    for (NewsItem newsItem : newsItemList) {

        String classe = newsItem.getClasse();
        String category = newsItem.getCategory();

            for (String filterClasse : filters) {

                if (classe.equals(filterClasse)){
                    filtredItemList.add(newsItem);
                }

    }

        for (String filterCategory : filters) {

            if (category.equals(filterCategory)){
                filtredItemList.add(newsItem);
            }
        }
    }



    if (filtredItemList.size() != 0 ) {
        callback.onNewsLoaded(filtredItemList);

    }   else  {
        callback.onDataNotAvailable();
    }


}




Aucun commentaire:

Enregistrer un commentaire