collapse all recycler view sections except one.. set image resource

152 views Asked by At

I am trying to collapse all sections in recyclerview except one ( currently selected).. I can collapse all items successfully.. but I want to reverse the arrow direction in headerholder.. I Using the library as https://github.com/luizgrp/SectionedRecyclerViewAdapter.. while reversing the arrow it is giving null pointer exception for headerholders out of window ( not visible in present screen)..

{
    for (int i = 0; i < deviceInfoList.size(); i++) {
        ExpandableDeviceSection section = (ExpandableDeviceSection) sectionAdapter.getSection(deviceInfoList.get(i).getdName());
        if (section.expanded && !section.dName.equals(dName)) {
            section.expanded = false;

            HeaderViewHolder headerViewHolder1=(HeaderViewHolder)recyclerView.findViewHolderForAdapterPosition(sectionAdapter.getHeaderPositionInAdapter(section.dName));
                            //getting null for sectionHeader which is not available.
            if(headerViewHolder1!=null)
                headerViewHolder1.imgArrow.setImageResource(section.expanded ? R.drawable.ic_expand_less : R.drawable.ic_expand_more);
        }
    }
//                    sectionAdapter.notifyDataSetChanged();
}

here is my all collapse code in onclick listener.. I hope this clarifies.. let me know if anything else required..

1

There are 1 answers

0
novrox On

Problem solved.. forgot to set image view (imagearrow) in onbindheaderview holder.. No need to set it in for loop now .