-
Notifications
You must be signed in to change notification settings - Fork 987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MapView unusable in a RecyclerView #588
Comments
This is a known issue and gets posted here frequently. Glad you found a solution! If we were to make changes to the map view, what should we change? |
MapView.java implements onDetachedFromWindow but not onAttachedFromWindow. What's currently destroyed in onDetachedFromWindow should be initialized in onAttachedToWindow so that the view can go through a lifecycle where it's detached then attached again. Like onStart/onStop or onResume/onPause for an Activity. |
well the issue is that stuff is currently destroyed in onDetached that cannot be recreated. It's more like we need a pause/resume mechanism, however that's not part of the View or ViewGroup lifecycle. setHasTransientState requires API 16 or newer. I'm adding this to the samples now to provide clarification and to the javadocs. This seems to be the only simple solution currently. |
…us versions, set mapView.setHasTrasientState(true). This is now set in the constructor
Contrary to a View within an Activity, which is only attached and detached once, Views within RecyclerView items may be attached/detached repeatedly, see RecyclerView.Adapter.onViewAttachedToWindow and RecyclerView.Adapter.onViewDetachedFromWindow.
The MapView does not handle the View lifecycle properly, basically what is undone in onDetachedFromWindow is not done in onAttachedToWindow so it can effectively be attached only once.
A workaround for this issue is to call setHasTransientState(true) on the recycler's item view that contains the mapView. Doing this will prevent the RecyclerView from attempting to reuse the view
The text was updated successfully, but these errors were encountered: