Comments (5)
Hi @grunk,
Thanks for your words, glad to hear that it's been useful to someone :)
I don't think you need to extend SectionedRecyclerViewAdapter, just set is as the RecyclerView adapter as usual.
You should create your sections with a method to filter the data. Make sure to call setVisible(false) if there is no data to be displayed for the section after the filter is applied.
Then in onQueryTextChange you should call the filter method for all the sections.
Let me know if you need any further clarification.
from sectionedrecyclerviewadapter.
Thanks i will try implementing a filter directly in the sections. I let you know ;)
from sectionedrecyclerviewadapter.
Ok , for those who are interested it's how i implemented it. It's far from an optimal solution but it works.
In the activity/fragment , implements SearchView.OnQueryTextListener
Then filter each section :
@Override
public boolean onQueryTextChange(String query) {
for(ServerSection sec : mSections) {
final List<String> filteredItem = filter(sec.getOriginalList(),query);
sec.update(filteredItem);
}
return true;
}
private List<String> filter(List<String> items, String query) {
query = query.toLowerCase();
if(query.isEmpty())
return items;
final List<String> filteredItemList = new ArrayList<>();
for (String item : items) {
final String text = item.toLowerCase();
if (text.contains(query)) {
filteredItemList.add(item);
}
}
return filteredItemList;
}
In each section i keep the original list of item and a filtered list. Each search update the filtered list of each section :
class ServerSection extends StatelessSection {
String mTitle;
List<String> mList;
List<String> mOriginalList;
public ServerSection(String title, List<String> list)
{
super(R.layout.rv_header,R.layout.rv_srvlist);
mTitle = title;
mOriginalList = new ArrayList<>(list);
mList = mOriginalList;
}
public List<String> getOriginalList()
{
return mOriginalList;
}
public void update(List<String> items)
{
mList = items;
mSectionnedAdapter.notifyDataSetChanged();
}
}
from sectionedrecyclerviewadapter.
Great work grunk, I will give some thought to it and see if it can be added to the library.
Will keep you posted, thanks!
from sectionedrecyclerviewadapter.
hey, I updated the library (version 1.0.4) with a method to retrieve the sections of the adapter (getSectionsMap).
I also added a full example of a SearchView with Sections to the demo app.
thanks again for your suggestion and for sharing your code!
from sectionedrecyclerviewadapter.
Related Issues (20)
- Is it possible to support Paging concept introduced in recent year? HOT 6
- Error adding to dependecies HOT 1
- How can I bind the Header view? HOT 1
- How can I get the Section header position? HOT 5
- Suggestion to add example-code on how to use empty-views HOT 2
- OnClick in onBindItemViewHolder does not work HOT 1
- How to get header position? HOT 1
- swipe to delete... HOT 3
- Design suggestion based on the following use case HOT 1
- Is using Section as HashMap key a good design? HOT 5
- Can we have SectionedRecyclerViewAdapter.getSectionItemViewTypeForAdapterViewType as static method? HOT 2
- Optimize onCreateViewHolder
- removeAllSections HOT 2
- How can I get position group of recyclerview? HOT 2
- FirstVisibleItem not change after I use notifyDataSetChange
- Collapse when section when open new one
- Is there a way to set section background,like a cardview style
- how to Expand first item by default ?
- New versions changelog addition. HOT 1
- How Section Support ItemTouchHelper for drag & drop DataItem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sectionedrecyclerviewadapter.