IntruderShanky/Sectioned-RecyclerView

How to hide section view?

iharshb opened this issue · 2 comments

I want to hide Section header view If section header text is empty.

I tried with removeSection() but it will also remove child views too. Is there any way to only hide section header view?

Hey man, this is an old issue and you probably figured it out. But for others coming here, I also had same issue so I simply set header header height to 0.

What I did following @ecy5maa , initially i kept the width to 0. When I wanted to see header i called hideHeaderView(boolean) a custom method.

@Override
    public SectionViewHolder onCreateSectionViewHolder(ViewGroup viewGroup, int i) {
        headerView= LayoutInflater.from(context).inflate(R.layout.custom_section_header, viewGroup, false);
        headerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0));
        return new SectionViewHolder(headerView);
    }
 public void hideHeaderView(boolean hide) {
        if (headerView != null) {
            if (hide){
                headerView.setVisibility(View.GONE);
                headerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0));
            }else {
                headerView.setVisibility(View.VISIBLE);
                headerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            }
        }
    }