question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expand/collapse on click doesn't seem to work in rc3

See original GitHub issue

First of all thank you for the awesome library.

After updating from rc2 to rc3, I’m struggling to get the collapse/expand on click behavior to work. (this worked as expected on rc2)

Code:

  1. Expandable item
public class GroupItem extends AbstractExpandableItem<GroupItem.GroupViewHolder, SimpleItem> {

    private static final int LAYOUT_RESOURCE = R.layout.group_layout;
    String title;

    public GroupItem(String title) {
        this.title = title;
        setExpanded(true);
    }

    @Override
    public boolean equals(Object o) {
        GroupItem comparedItem = (GroupItem) o;
        return (comparedItem.title.equalsIgnoreCase(title));
    }

    @Override
    public int getLayoutRes() {
        return LAYOUT_RESOURCE;
    }



    @Override
    public GroupViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
        return new GroupViewHolder(view, adapter);
    }

    @Override
    public void bindViewHolder(FlexibleAdapter adapter, GroupViewHolder holder, int position, List payloads) {
        holder.tvTitle.setText("----" + title);
    }

    // View holder class
    public static class GroupViewHolder extends ExpandableViewHolder {

        public TextView tvTitle;

        public GroupViewHolder(View view, FlexibleAdapter adapter) {
            super(view, adapter);
            this.tvTitle = view.findViewById(R.id.tvTitle);
        }

    }
}
  1. Sub Item
public class SimpleItem extends AbstractFlexibleItem<SimpleItem.SimpleViewHolder> {

    private static final int LAYOUT_RESOURCE = R.layout.simple_layout;

    String title;

    public SimpleItem(String title) {
        this.title = title;
    }

    @Override
    public boolean equals(Object o) {
        SimpleItem comparedItem = (SimpleItem) o;
        return (comparedItem.title.equalsIgnoreCase(title));
    }

    @Override
    public int getLayoutRes() {
        return LAYOUT_RESOURCE;
    }

    @Override
    public SimpleViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
        return new SimpleViewHolder(view, adapter);
    }

    @Override
    public void bindViewHolder(FlexibleAdapter adapter, SimpleViewHolder holder, int position, List payloads) {
        holder.tvTitle.setText(title);
    }

    // View holder class
    public static class SimpleViewHolder extends ExpandableViewHolder {

        public TextView tvTitle;

        public SimpleViewHolder(View view, FlexibleAdapter adapter) {
            super(view, adapter);
            this.tvTitle = view.findViewById(R.id.tvTitle);
        }

    }
}
  1. Adapter with mock data
        List<GroupItem> groupList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            GroupItem newGroup = new GroupItem("Group " + i);
            for (int j = 0; j < 6; j++) {
                SimpleItem simpleItem = new SimpleItem("Item" + i + " " + j);
                newGroup.addSubItem(simpleItem);
            }
            groupList.add(newGroup);
        }

        adapter = new FlexibleAdapter<GroupItem>(groupList);
        adapter.expandItemsAtStartUp();
        recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(this));
        recyclerView.setAdapter(adapter);

Result:

  • Clicking the group items doesn’t trigger any action
  • Calling setExpanded(true) and expandItemsAtStartUp() shows both expandable and subitems. Without these I only see the expandable items.

Am I missing anything here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
davideascommented, Oct 31, 2017

@wildmelon, the correct way to link the listener to an item view is by adding the listener to the adapter as @cioraneanu does or in the Constructor, the difference as new feature is that now when added and removed separately at runtime, there’s a routine that identifies all the already bound view holders and link the listener to them. You can read more here (#427 - Dynamically add and remove listeners).

@cioraneanu, please read again my previous answer (now edited) since it was wrong.

1reaction
cioraneanucommented, Oct 31, 2017

@wildmelon Your proposed solution works. Adding a click listener on the adapter seems to do the job as well. adapter.addListener(new FlexibleAdapter.OnItemClickListener(){

Read more comments on GitHub >

github_iconTop Results From Across the Web

expand / collapse doesn't work on heading if it's set later
In the screenshot attached you can see that while the text is set as heading 2 it doesn't show the expand / collapse...
Read more >
Bootstrap Collapse not Collapsing - Stack Overflow
The "Collapsible Group Item #1" when clicked should collapse the items in class "panel-body" but it doesn't there is no effect of click....
Read more >
Solved: Expand/Collapse Group not working in Quizzes
The "Expand/Collapse Group" button is not working for me once a quiz is saved (it works fine during quiz creation). Is this a...
Read more >
Expand/collapse problem - JavaScript - SitePoint Forums
Some time ago, if I remember thanks to you, I made a new expand/collapse solution in js and css. The js is: $(".expandable").on("click", ......
Read more >
Having problems with collapse and expand elements - Wix.com
It was working just fine and since 3 days ago is not working anymore. ... tried and still didn't work, it stays collapsed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found