Closed meshileya closed 6 years ago
@meshileya
Let me assume your Section
is always in State.LOADED
, to make the discussion easier. Here's what you can do.
Once you perform click in your header, set itemShouldBeHide
= true
, in SharedPreference
(Or any other place, which can be easily accessible by your Section)
Use the following function call, to trigger onBindItemViewHolder
in your Section.
final int contentItemsTotal = section.getContentItemsTotal(); sectionedRecyclerViewAdapter.notifyItemRangeChangedInSection( section, 0, contentItemsTotal );
3. In your `Section`'s `onBindItemViewHolder`, has the following logic
if (itemShouldBeHide) { holder.itemView.setVisibility(View.GONE); } else { holder.itemView.setVisibility(View.VISIBLE); }
Let's me know if such approach work. Thanks.
@yccheok thanks so much, i sincerely do appreciate. I was able to make it work with your explanation
I did like to ask, how i can use filtering to filter items under a particular header being fetched from the database. For instance, items created on April should be under April, while that of May should be under May, i.e. each item are being pulled from a remote server and filtered on the recyclerview.
I don't know if you understand the question, pls.
It is not the responsible of SectionedRecyclerAdapter
to perform filtering.
However, use SectionedRecyclerAdapter
, coupled with Android Architecture Components (LiveData, ViewModel, Room), you can achieve desired outcome.
You may refer to this excellent tutorial : https://www.youtube.com/watch?v=SlZVYkhoSq8 She teaches how to perform filtering based on search term, using Android Architecture Components. I had tried them in my production project. They works pretty well together with SectionedRecyclerAdapter
Let's me show you an example
For the above, I need to first perform filter based on "Home" label. Then, I need to filter again based on "Pinned" and "Others". All these are performed using Android Architecture Components.
For "Pinned" section and "Others" section, they are implemented using SectionedRecyclerAdapter
's Section
.
@yccheok @luizgrp
I did like to ask how i can go about the implementation of hiding the items under a particular header, once it has been clicked.
headerHolder.itemView.setOnClickListener(view -> Log.w("Header", "Items should Hide"));
Once that action is being triggered, i did like all the items to hide under that particular header, and once it is clicked again...all items should show.
Thanks.