florent37 / ExpansionPanel

Android - Expansion panels contain creation flows and allow lightweight editing of an element.
https://material.io/guidelines/components/expansion-panels.html
Apache License 2.0
1.98k stars 240 forks source link

Add an option to not set click listener on the header by default #59

Open Peterragheb opened 4 years ago

Peterragheb commented 4 years ago

I wanted to keep track of the expanded item position. Using the default expansion listener didn't work. So I had to write my own onClickListener which was not possible because you set it by default in the header class. I had to create my custom header to remove the clickListener and add my own clicklistener in the recyclerview adapter. Can you also please make it that when calling .expand() or .collapse() with false as the parameter to reset the indicator without animation too.

        if (isExpanded)
            holder.binding.expansionLayout.expand(false);
        else
            holder.binding.expansionLayout.collapse(false);
        expansionsCollection.add(holder.binding.expansionLayout);
        holder.binding.ehHeader.setActivated(isExpanded);
        holder.binding.ehHeader.setHeaderRotationCollapsed(0);
        holder.binding.ehHeader.setHeaderRotationExpanded(180);
        holder.binding.ehHeader.setOnClickListener(v -> {
            if (isEnabled){
                mExpandedPosition = isExpanded ? -1: position;
                holder.binding.expansionLayout.toggle(true);
            }
        });
mattcrwi commented 4 years ago

I also was looking for a way to set a custom click handler on the header. I ended up setting it in .doOnAttach because the default is set in onAttach and mine would be set after.