根据ListView中回收items机制的概念
实际上,我想知道如何检测 View
离开屏幕 的时刻。
我解释一下为什么。
在大多数情况下 ListView
有一个自定义的
Adapter(? extends ArrayAdapter/? extends BaseAdapter, etc.).
getView(...)
方法允许操作 View 的可见性和内容(文本、位图、可绘制对象等)
在某些情况下,我需要启动一个单独的线程来执行
后台工作,然后更新 UI。实际上 - 使用 AsyncTask。
当我在 ListView
中有很多项目时,每次调用 getView 都会产生一个新的 Thread
。如果 View
不再出现在屏幕上,我需要取消它们。这个怎么做?
最佳答案
您可以覆盖 onDetachedFromWindow对于 View 。这会让您知道 View 何时离开屏幕。文档说:
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.
另见 onAttachedToWindow()
关于android - 如何检测 ListView 项目变为 ActiveView(离开屏幕)的时刻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33403366/