luizgrp / SectionedRecyclerViewAdapter

An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
MIT License
1.68k stars 372 forks source link

How to Filter section item listview elements based on Comparator #33

Closed NathiyaK closed 5 years ago

NathiyaK commented 7 years ago

I have issue in Section Item filtering based on Comparator.

I have used the below code for filtering in section itemview layout. In my code my section item view has an recyclerview with list of elements.

for (Section section : sectionAdapter.getSectionsMap().values()) {

                    if (section instanceof FilterableSection) {
                        ((FilterableSection) section).filteratoz();
                    }
                }
                sectionAdapter.notifyDataSetChanged();  

In my section adapter i have user the below codes interface FilterableSection { void filteratoz(); }

public void filteratoz(){ for (Categorysubcatmodel value : filteredList) { Collections.sort(filteredList, new Comparator() { public int compare(Categorysubcatmodel v1, Categorysubcatmodel v2) { return v1.getName().compareTo(v2.getName()); } }); } sectionAdapter.notifyDataSetChanged();

    }

filteredList - Array List which has data items in it. If i run the app i have got the below exception:

java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573) at com.halal.travel.fragments.Thingsfragment$HeaderRecyclerViewSection1.filteratoz(Thingsfragment.java:1383) at com.halal.travel.fragments.Thingsfragment$2.onClick(Thingsfragment.java:318) at android.view.View.performClick(View.java:5207) at android.view.View$PerformClick.run(View.java:21177) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5438) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

luizgrp commented 5 years ago

Closing due to inactivity, please open a new issue using a proper template if you are still having problems.