Comments (5)
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.
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.
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.
I solved it. Can be closed.
from expandable-recycler-view.
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)
- Unable to Clear Child Item of Particular Parent
- Improve RecyclerView adapter change animations HOT 1
- Internal lib crash
- ChildViewHolder with RecyclerView. LazyLoad
- notifyChildRangeInserted not working
- Odd behavior when starting animations in onExpansionToggled
- How to scroll recyclerview to selected parent position HOT 1
- How to limit child size
- how to change the view when clicking parent item
- Expandable Recyclerview is collapsing views when we update dataset HOT 1
- Change childcard depending on view clicked in parentcard
- two child in row
- How to show initially all views(parent & Child view) in expanded state HOT 1
- How to implement parent & child view search
- realm-expandable-recycler-view for, Inconsistency detected
- Facing issue while using linearLayoutManager.setReverseLayout(true)
- How to scroll recyclerview to particular position?
- How To scroll ExpandableListview inside NestedScrollView ?
- at parent position (0) update child list
- Delete item from recycler view
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expandable-recycler-view.