Comments (12)
Yilzer
I'm implementing saved state for the StickyHeaderLayoutManager. It likely won't be completely automatic, though. You'll still need to explicitly pack and restore state in your activity's onSaveInstanceState, etc. See here: http://stackoverflow.com/questions/28236390/recyclerview-store-restore-state-between-activities -- I'll report when I've got this working.
Regarding your first point, about jumping to position, this is an interesting quandary. When you request smoothScrollToPosition or scrollToPosition, you're passing an adapter position, which includes headers (and "ghost headers", used internally by the library). This means that if you're looking at the first item of the first section, your adapter position would actually be 3.
I think your best bet there is to ask the adapter for the adapter position, e.g.:
showItem(int clickedIndex) {
int section = ... // you need to determine which section you're dealing with
int adapterPosition = adapter.getAdapterPositionForSectionItem(section, clickedIndex)
recyclerView.scrollToPosition(adapterPosition)
}
from stickyheaders.
I was away on vacation until yesterday - sorry for the delay.
After doing some research, it's clear that scrollToPosition is implemented in the LayoutManager, not RecyclerView. I'll get cracking on it, as well as smoothScrollToPosition.
from stickyheaders.
Thx for your response,
When you're working on scrollToPosition it may also be important to save the scroll position in onsaveInstance. You can do this by calling: currPosition = recyclerView.findFirstVisibleItemPosition();
The findFirstVisibleItemPosition() method is also an method in the linearlayout manager. I think it's important to have this part also in your stickylayout manager.
Keep up the good work!
from stickyheaders.
yilzer,
I've implemented scrollToPosition
and smoothScrollToPosition
in the adapter, and they appear to work though I will be testing them further. That being said, I have a serious performance issue with HUGE datasets (hundreds of sections, thousands of items) which I want to tackle before I push an update to bintray. I expect to have that taken care of in a couple days, and I'll let you know and close this issue.
from stickyheaders.
I've also fixed a huge performance problem, so I'll be posting an update to bintray tonight, or so.
from stickyheaders.
Great work man, i've just two more questions for you:
- if i have 20 items with sticky header in my adapter, when i press on item 3 in grid. I want to show item 3 in adapter, but it shows item 1. Do you have an solution for this, so that it scrolls to the exact item.
(What i do now to achieve this is multiply the pressed item with 3, i don't know if this is the recommended solution) - If i leave my activity or fragment i want to save the item that is visible to the user when leaving, so i can scroll back in onsaveinstance to the last visible item how does this works in your stickylayoutmanager?
Thanks in advance!
from stickyheaders.
Thanks man!
int section = ... // you need to determine which section you're dealing with
How do i determine the section index? , because the only value that i have at that moment is the value that i want to show to the user in the adapter.
from stickyheaders.
First, I've implemented saved state and it appears to work.
Now, regarding your question, I guess I need to understand the problem. I'm parsing your usage as having one recyclerview -- and when users tap an item in it, the recycler scrolls that item to top of the viewport?
That being said, I've realized the fix is easier than I thoguht: as you have a reference to the ViewHolder, just use RecyclerView.ViewHolder::getAdapterPosition()
.
from stickyheaders.
Great work man, I have an fragment with grid images , when the user taps on one of the images he goes to an new activity with your adapter (sticky layout manager). Inside this activity the images are displayed like an feed ( large images instagram style). So if the user taps on item 3 i want to show item 3 in feed with large images.
So i retrieve the current item position from the grid fragment and want to determine the scroll position to show that item to the user.
showItem(int clickedIndex) { int section = ... // you need to determine which section you're dealing with int adapterPosition = adapter.getAdapterPositionForSectionItem(section, clickedIndex) recyclerView.scrollToPosition(adapterPosition) }
How should i determine the section(int section = ... // you need to determine which section you're dealing with) if the only item that i have is the item position from the gridfragment.
I hope you understand my issue better now.
from stickyheaders.
So, if I understand correctly, what you have is a grid of items, indexed 0..N. Clicking on an item opens a list-like recyclerview detail using StickyHeaderLayoutManager where you have all those items, (0..N] but each is presented with its own header, where (presumably) the header is showing the item title/date/other-metadata. In your SectioningAdapter, each item gets its own section, with an associated header. So you have a list mapping like so:
[Header 0,(GhostHeader 0),Item 0],[Header 1,(Ghost Header 1), Item 1]...[Header N, (Ghost Header N),Item N]
(Ghost headers are created by the adapter as part of the layout process)
In this case, the need to multiply item index by 3 makes perfect sense. However: there's a semantically meaningful and forward-compatible way to handle this: instead of trying to scroll to the item, what you want is to scroll to the item's header. The header is indexed by section. So, here's what you will want to do:
void scrollToItem(int itemIndex) {
int adapterPosition = adapter.getAdapterPositionForSectionHeader(itemIndex)
recyclerView.scrollToPosition(adapterPosition);
}
from stickyheaders.
Great work again! This solved all my issues for now. This item can be closed!
from stickyheaders.
Fantastic, glad I could help.
from stickyheaders.
Related Issues (20)
- Class cast exception after upgrading to android x HOT 1
- Disabling item section collapsing on open HOT 2
- Publish version 0.7.9 to Maven HOT 4
- IndexOutOfBoundsException HOT 6
- How to set setStackFromEnd??
- Accessibility using StickyHeaders HOT 1
- App Crashing If the List size is 0. HOT 2
- Custom Scroll Behaviour
- wrap_content not working
- notifySectionItemChanged() crashes the app
- How to include grid layout with sticky headers ?
- This lib doesn't seem to support clipToPadding = false on RecyclerView
- Item size 0 , crash the app. HOT 1
- jcenter is deprecated. Move to mavencentral HOT 2
- how to get the current sticky section?
- StickyHeaderLayoutManager doesn't display scroll bars HOT 4
- Refactor AndroidX HOT 5
- StickyLayoutManager does not work in kotlin and recycler view appears empty HOT 1
- when user scroll the page, data changed in rows !
- Some problems when use this with smartRefreshLayout
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 stickyheaders.