Comments (6)
That might make sense. But consider this scenario.
You have 10 elements in the adapter and side buffer is set to 1 and you're currently focusing on element 5. Hence, ViewFlow has loaded view 4, 5, 6. Then, let's assume setSelection(1)
is called. That would result in the currently loaded views: 0, 1, 2, hence, the previously shown View 5 is not loaded any more.
Question: What would be passed as previousView
in the new onSwitched method?
I am very tempted to answer null
on that since the ViewFlow has removed the view from the buffer and should hold no reference to it. Passing a view that is expected to be freed from memory doesn't sound too good.
from android-viewflow.
I agree with this, and passing null
will also prevent memory leaks caused by references on the application side. Some might view null
-valued parameters as poor API design, however. Google does it anyway, such as in adapter-view binding.
from android-viewflow.
I have the fix almost done but need to close down for the evening. Hopefully I will push it tomorrow.
from android-viewflow.
Thanks. I was just thinking that a second callback might be more appropriate, since taking these references might influence GC unnecessarily... for example, if you take a reference to the view prior to removing it from the buffer. But checking for this case would also prevent that.
from android-viewflow.
First of all, a previous view will never be passed if it was just removed.
But we still might have the case that a view is removed later on, if the user is storing a reference to the view or doing some asynchronous task. But this issue is applicable for the current view as well. Separating the interface into two callbacks won't solve that problem I think. We need to remember that ViewFlow
is re-using old View
s as well when appropriate. Therefore, modifying a View
from a ViewSwitchListener
asynchronously might have strange effects if ViewFlow
is trying to re-use the View
before the asynchronous task is complete.
If you have control over both the ViewSwitchListener
and the Adapter
you can avoid these situations by checking which View
is being re-used when the getView(...)
method is called in the Adapter
. Better yet, if you can modify the View
synchronously, this will never occur.
I should probably clarify things in the Javadoc for the ViewSwitchListener
.
from android-viewflow.
Implementing this in postViewSwitched
(which is called when the user swipes) is very straight-forward. But I just figured out, doing this in setSelection
requires bigger changes. In setSelection
I'm taking a shortcut and remove all views from the buffer, and then request to get a new view from the adapter for each element. Of course re-using the actual view objects, but still, if I would simply save the previous view in the beginning of setSelection
, that view would no longer correspond to the previous view as it has been re-used by another (arbitrary) element.
I certainly need to re-do setSelection
anyway because it is very sub-optimal. Especially if someone uses setSelection
to just go back and forth one view at a time, as setSelection
will ask the adapter for all views and not really make use of the buffer.
from android-viewflow.
Related Issues (20)
- adapter getview position always return 0?
- How to make the margin between images become zero? HOT 1
- how to run the examples ?
- "ant jar" build failure
- how to adjust the sensitivity of the switching bewteen views?
- native typeface cannot be made
- Inflate the same Layout?
- viewflow cause memory leak? HOT 2
- Unable to set Text for other layout HOT 1
- the return value of method getSelectedItemPosition() is not refreshed instantly
- NullPointerException occurs randomly while scrolling
- Increase Size of CircleFlowIndicator HOT 1
- ViewFlow displays only one title for Holo Light Theme.
- Request
- How to add Settings in DiffViewFlow
- the master version can`t support API below Level 11 HOT 13
- java.lang.NoSuchMethodError: android.view.View.getMeasuredState HOT 2
- view flow inside list view HOT 1
- Problem on ExpandableListView HOT 1
- IndexOutOfBoundException HOT 1
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 android-viewflow.