Git Product home page Git Product logo

Comments (5)

mandybess avatar mandybess commented on August 20, 2024

@HoLuong0211 I would recommend using one of the adapter.toggleGroup() methods to toggle a group. This will ensure the expandCollapseController is aware of the expanded / collapsed state of all groups. The adapter uses this class to determine whether to call expand or collapse animations. So if that controller becomes out of sync, that is one reason why you might be seeing the wrong animations being called.

from expandable-recycler-view.

HoLuong1609 avatar HoLuong1609 commented on August 20, 2024

@mandybess I replaced onGroupClick(holder.getAdapterPosition()); method by toggleGroup(holder.getAdapterPosition()) but it still the same, my indication arrow still not animate the right way.
Could you please explain with a little more detail about your idea for this issue.

Thank you for your help!

from expandable-recycler-view.

mandybess avatar mandybess commented on August 20, 2024

If you are calling this method inside onCreateGroupViewHolder then all of the work is being executed before the group click listener is applied to the group view holder. That might be why you are experiencing some weirdness. I would recommend calling toggleGroup after the adapter has had a chance to create and bind all view holders

from expandable-recycler-view.

HoLuong1609 avatar HoLuong1609 commented on August 20, 2024

@mandybess I moved all code from ChatGroupAdapter to my Activity:

List<ParentExpandable> expandableList = getListChatGroup(); final ChatGroupAdapter adapter = new ChatGroupAdapter(this, expandableList); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); if (adapter.getGroups().size() > 0) { new Handler().postDelayed(new Runnable() { @Override public void run() { for (int i = 0; i < adapter.getGroups().size(); i++) { ChatGroupParentVH holder = (ChatGroupParentVH) recyclerView.getChildViewHolder(recyclerView.getChildAt(i)); adapter.toggleGroup(holder.getAdapterPosition()); holder.expand(); } } }, 1000); }

The group items was expanding for the first time and the indication arrow animate the right way, but when I click on the indication arrow for the second time it still when to ChatGroupParentVH.expand() method.
Or maybe I didn't get your idea. Could you please explain your solution for this issue.

Thank you so much!

from expandable-recycler-view.

vfa-tuantt avatar vfa-tuantt commented on August 20, 2024

I have solution for you @HoLuong1609

Step 1: after recyclerView.setAdapter(adapter); Please set adapter.toggleGroup()
Step 2: In function onBindGroupViewHolder of Adapter please check:

boolean isExpand = isGroupExpanded(flatPosition);
if(group instanceof ChatGroupParentVH){
         if(isExpand){
               ((ChatGroupParentVH) holder).animateExpand(0);
         }else {
               ((ChatGroupParentVH) holder).animateCollapse(0);
         }
 }

You can reference the code of animateExapand in below

public ObjectAnimator createRotateAnimator(final View target, final float from, final float to, int duration) {

        ObjectAnimator animator = ObjectAnimator.ofFloat(target, "rotation", from, to);
        animator.setDuration(duration);
        animator.setInterpolator(Utils.createInterpolator(Utils.LINEAR_INTERPOLATOR));
        return animator;

}
private void animateExpand(int duration) {
        createRotateAnimator(view, 0f, 180f,duration).start();
}

private void animateCollapse(int duration) {
        createRotateAnimator(view, 180f, 0f,duration).start();
}

It's worked for me

from expandable-recycler-view.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.