Giter VIP home page Giter VIP logo

Comments (5)

paul-turner avatar paul-turner commented on June 16, 2024

Right now there isn't a very simple way, but I think the following should be possible:
given the position that you have you can access the mItemList variable in your adapter and get the item at that position. From there if it is an instanceof ParentWrapper then you have a Parent Item, if not it is a child. If it is a ParentWrapper you should be able to get the ParentItem it is wrapping which will help you add/remove it with our notify methods.

Hopefully that helps. I'll be thinking of ways to simplify this interaction, welcome any ideas.

from expandable-recycler-view.

XxGoliathusxX avatar XxGoliathusxX commented on June 16, 2024

Hey @paul-turner,
here is a quick example what the problem is:
Example: Every parent has one child.
P0
P1
When I swipe P1 and none is expanded, the returned position is 1.
Now if P0 is expanded:
P0
C1
P1
When I swipe C1 the returned position is 1 too.
When I swipe P1 instead the position is 2.

So i have to know which parents are expanded to count to the position of the swiped item.
I imagined to add a variable to each parentItem "isExpanded". If a click in the OnClickListener is detected, the value changes. The OnClickListener is implemented in the ParentViewHolder.
Here:

public ExpParentViewHolder(View itemView) {
super(itemView);
mTitleTextView = (TextView) itemView.findViewById(R.id.parent_list_item_title_text_view);
mParentDropDownArrow = (ImageButton) itemView.findViewById(R.id.parent_list_item_expand_arrow);
mParentDropDownArrow.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View v) {
if (isExpanded()) {
collapseView();
} else {
expandView();
}
}
});
}

from expandable-recycler-view.

paul-turner avatar paul-turner commented on June 16, 2024

I think my previous answer still holds the most value to you.

mItemList in the expandable adapter holds all the items represented in the RV (A combination of ParentWrappers that hold a reference to your ParentItem and the bare Child Object).

In example your it would hold:

0: ParentWrapper holding P0
1: ParentWrapper holding P1

when you expand P0 it will then be updated to hold

0: ParentWrapper holding P0
1: Child Object C1
2: ParentWrapper holding P1

So given the index if you pull out the object from mItemList you will be getting the parent or child that was swiped on. From there a couple of instanceof checks should get you the information you need about what parent or child object it is (probably by comparing the P0 or C1 object to what you have in your list of ParentItems.

Hopefully that clears up my previous answer, I think it will be easier than keeping track of the individual states yourself. Also the ParentWrapper objects in that list hold the isExpanded state you mention, so that might be what you want in all as well (just make sure that you note the children are also in that list when traversing, not all objects are ParentWrappers all the time in mItemList)

from expandable-recycler-view.

XxGoliathusxX avatar XxGoliathusxX commented on June 16, 2024

I solved it. Can be closed.

from expandable-recycler-view.

Anu07 avatar Anu07 commented on June 16, 2024

Hi Can You help me with the solution that you found for above scenario? I am not having viewtypes for my parent and child

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.