问题
According to concept of recycling items mechanism in ListView.
I want to know, actually, how i can detect a moment when a View
going off-screen.
I explain why.
In most cases ListView
have a custom Adapter(? extends ArrayAdapter / ? extends BaseAdapter, etc.).
getView(...)
method allows to manipulate visibility and content of views (text,bitmaps,drawables,etc.)
And in some cases i need to launch a separate Thread which doing
background work, and after that update UI. Actually - using AsyncTask.
When i have many items in ListView
each call of getView will be produced start a new Thread
. I need to cancel them if View
is no more longer present on the screen. How to do this?
回答1:
You can override onDetachedFromWindow for the view.This will let you know when the view is going off-screen.The docs says:
protected void onDetachedFromWindow ()
Added in API level 1 This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
See Also onAttachedToWindow()
来源:https://stackoverflow.com/questions/33403366/how-to-detect-a-moment-when-listview-item-becomes-activeview-going-off-screen