How to detect a moment when ListView item becomes ActiveView (going off-screen)

限于喜欢 提交于 2020-01-03 03:25:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!