Comments (6)
hi @IlanVokov ! What Fragment lifecycle call backs were you trying??
from expandable-recycler-view.
onSaveInstanceState to save as you do, and there is no onRestoreInstanceState in fragment so i try inside onCreateView
from expandable-recycler-view.
I know I'm a little late but today I managed to sort this problem out so thought it would be good to share the solution.
So basically the idea is in onCreate method to either load items list from a savedInstance between rotation changes OR if app was launched first time, savedInstance will be null so fragment needs to retrieve items ist from network.
in onCreate method you either load your itemsList from savedInstance or network.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
itemsList = savedInstanceState.getSerializable("ITEMS");
adapter = new Adapter(itemsList);
adapter.onRestoreInstanceState(savedInstanceState);
} else {
//Do your network calls, retrieve items list and instantiate adapter
}
In onCreateView you bind your adapter to recyclerView.
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//Inflate view, create recyclerView/Adapter references
//Create adapter by using itemsList (either retrieved from network or from your savedInstance)
//Bind adapter to recyclerView
}
In onViewStateRestored you just tell your adapter to to refresh the view with your saved itemsList
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null)
adapter.onRestoreInstanceState(savedInstanceState);
}
in onSaveInstance you save your current itemsList during fragment/rotation changes
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
adapter.onSaveInstanceState(outState);
outState.putSerializable("ITEMS", itemsList);
}
And that's about it. Also I noticed if I navigate from this current fragment (let's call it fragment A) by using '.replace' (in your FragmentManager) to a Fragment B, then if in Fragment B I use 'popBackStack' it will bring me back to Fragment A and the previous state will be restored again! Which is perfect for me because I wanted to save expanded list state throughout rotation changes as well as fragment navigation changes.
Also don't be afraid to override all lifecycle methods called in fragment and print out logs. That really helped me do understand the lifecycle flow and where to make changes.
Reference which might help: https://developer.android.com/guide/components/fragments#Design
from expandable-recycler-view.
Sorry, Can you question ?
About lost state when ExpandableRecycleview scrolls then All it`values will be wrong.
Example
When 1 item VISIBLE or GONE . when I scroll . VISIBLE AND GONE wrong.
Thankyou
from expandable-recycler-view.
@haiminhtran810 Sorry I dont understand. Ask your friend who speaks english to clarify.
from expandable-recycler-view.
@eurbon Sorry you
I encountered a case that when I scroll down/up it loses state
For example :
I have a List (1: visible , 2 visible,3 visible, 4 visible, 5 visible, 6 invisible)
I have a layout_item_parent
Include :
ImageView ( invisible or visible ) and TextView.
But when I dont scroll, Imageview is visible . Then I scroll down then i scroll up. Show ImageView wrong
It change to visible to Invisible
Sorry you. My weak English
from expandable-recycler-view.
Related Issues (20)
- when i click on artist itemview and back again recycler view is gone HOT 1
- Add data from api
- Is it possible to put single and multiple check items in one recyclerview?
- Display the same background for Childs
- MultiTypeExpandableRecyclerViewAdapter automatically use animation in OnStart method
- How to use it with Paging HOT 1
- Tried to use preview panel provider (JavaFX WebView), but it is unavailable. Reverting to default
- There is a `toggleGroup` function which will expand a group if it is collapsed
- collapse will be called automaticly when start activity. HOT 1
- Duplicate child when expanding parents multiple times (latest release) HOT 1
- why child's default interval is big and how to setting?
- Strange Behavior on Dynamic Group Header Size
- EXPAND_STATE_MAP is private
- Migrate away from jCenter HOT 5
- Element Sorting
- When app not used for a while, expandablerecyclerview menus are empty HOT 1
- Expand and collapse smoothly HOT 1
- Allow me push access...I have updated the project to latest environment
- Error dowloading library HOT 1
- Unable to add lib in new created project (Android Studio Giraffe | 2022.3.1) HOT 2
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.