thoughtbot / expandable-recycler-view

Custom Android RecyclerViewAdapters that collapse and expand
https://robots.thoughtbot.com/introducing-expandablerecyclerview
MIT License
2.12k stars 407 forks source link

Expand one row of list #25

Closed ashwini-pandarkat1993 closed 7 years ago

ashwini-pandarkat1993 commented 8 years ago

Hi, I want expand only one item at a time when I click on another list item previous should automatically collapse.

yelamansa commented 7 years ago

@ashwini-pandarkat1993 Did you get a solution?

mandybess commented 7 years ago

Hiya! Here is one solution:

    private ExpandableGroup expandedGroup;

    adapter.setOnGroupExpandCollapseListener(new GroupExpandCollapseListener() {
      @Override
      public void onGroupExpanded(ExpandableGroup group) {
        if (expandedGroup != null) {
          adapter.toggleGroup(expandedGroup);
        }
        expandedGroup = group;
      }

      @Override
      public void onGroupCollapsed(ExpandableGroup group) {

      }
    });
yelamansa commented 7 years ago

Thank you very much!

2017-01-27 6:34 GMT+06:00 Amanda Hill notifications@github.com:

Closed #25 https://github.com/thoughtbot/expandable-recycler-view/issues/25.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/thoughtbot/expandable-recycler-view/issues/25#event-938682201, or mute the thread https://github.com/notifications/unsubscribe-auth/APfNKMAjS5jBGpJ2cRkh-5BRrXmGIYQNks5rWTuwgaJpZM4K9jA5 .

-- С уважением, Айтымбет Еламан

JayattamaPrusty commented 7 years ago

what should be written in adapter.toggleGroup(expandedGroup). As only integer value can be invoked into toggleGroup(int flatPos). how to get the position of an expanded group.

mandybess commented 7 years ago

@JayattamaPrusty there is also a method to pass an ExpandableGroup into toggleGroup()

https://github.com/thoughtbot/expandable-recycler-view/blob/master/expandablerecyclerview/src/main/java/com/thoughtbot/expandablerecyclerview/ExpandableRecyclerViewAdapter.java#L185

JayattamaPrusty commented 7 years ago

@mandybess its not working for me.here i m facing a problem that when i expand one group,if i try to expand another group,its not expanding.after collapsing first group also no other groups not working.

JayattamaPrusty commented 7 years ago

how to add onclicklistener on child item?

rahulyadav7001 commented 7 years ago

Hi @mandybess, This code is working for me,but after adding this code in setOnGroupExpandCollapseListener method I'm getting crass after clicking two three time of any items. Please help me.

ghost commented 7 years ago

@rahulyadav7001 change line to: if (expandedGroup != null && !expandedGroup.equals(group)) {

kukamanga commented 7 years ago

@rahulyadav7001 This should solve your problem:

private ExpandableGroup mLastExpandedGroup ; @Override public void onGroupExpanded(ExpandableGroup group) { if (mLastExpandedGroup != null && !mLastExpandedGroup.equals(group) && adapter.isGroupExpanded(mLastExpandedGroup)) { adapter.toggleGroup(mLastExpandedGroup); } mLastExpandedGroup = group; }

bobcripps commented 7 years ago

I too want to be able to close an expanded group automatically when another one is opened. I'm probably missing something here but I've implemented the onGroupExpanded() listener in the Activity in the sample in ExpandActivity and it works but the rotation of the up down arrow is done in the GenreViewHolder hence the group is collapsed correctly but I don't know how to get the GenreViewHolder to rotate the arrow. There appears to be no way to link the ExpandableGroup to the GenreViewHolder. adapter.setOnGroupExpandCollapseListener(new GroupExpandCollapseListener() { @Override public void onGroupExpanded(ExpandableGroup group) {

    if (expandedGroup != null
            && !expandedGroup.equals(group)
            && adapter.isGroupExpanded(expandedGroup)) {
      adapter.toggleGroup(expandedGroup);
    }
    expandedGroup = group;
  }
shwetantmohapatra commented 6 years ago

can some one help me with this

pavelsust commented 5 years ago

@mandybess its not working for me.here i m facing a problem that when i expand one group,if i try to expand another group,its not expanding.after collapsing first group also no other groups not working.

ya i am facing this issue too

RealDavid commented 4 years ago

Best solution.

` private ExpandableGroup expandedGroup;

productAdapter.setOnGroupExpandCollapseListener(new GroupExpandCollapseListener() {
    @Override
    public void onGroupExpanded(ExpandableGroup group) {
        if (expandedGroup != null) {
            productAdapter.toggleGroup(expandedGroup);
        }
        expandedGroup = group;
    }

    @Override
    public void onGroupCollapsed(ExpandableGroup group) {
        expandedGroup=null;
    }
});

expandableRecyclerView.setAdapter(productAdapter);

}`