如何检测ListView项变为ActiveView的时刻(移出屏幕) [英] How to detect a moment when ListView item becomes ActiveView (going off-screen)

查看:83
本文介绍了如何检测ListView项变为ActiveView的时刻(移出屏幕)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据ListView中的回收项目机制的概念.

According to concept of recycling items mechanism in ListView.

实际上,我想知道如何检测View 离开屏幕的时刻.


我解释原因.

I want to know, actually, how i can detect a moment when a View going off-screen.


I explain why.

在大多数情况下,ListView具有自定义
Adapter(? extends ArrayAdapter / ? extends BaseAdapter, etc.).

In most cases ListView have a custom
Adapter(? extends ArrayAdapter / ? extends BaseAdapter, etc.).


getView(...)方法允许操纵视图的可见性和内容(文本,位图,可绘制对象等)


getView(...) method allows to manipulate visibility and content of views (text,bitmaps,drawables,etc.)

在某些情况下,我需要启动doing后台工作的单独线程,并在更新UI之后.实际上-使用AsyncTask.

And in some cases i need to launch a separate Thread which doing background work, and after that update UI. Actually - using AsyncTask.

当我在ListView中有许多项目时,将产生每个 getView 的调用,开始一个新的Thread.如果View不再出现在屏幕上,我需要取消它们.这该怎么做?

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?

推荐答案

您可以覆盖

You can override onDetachedFromWindow for the view.This will let you know when the view is going off-screen.The docs says:

受保护的空白 onDetachedFromWindow()

在API级别1中添加. 窗户.此时,它不再具有要绘制的表面.

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()

See Also onAttachedToWindow()

这篇关于如何检测ListView项变为ActiveView的时刻(移出屏幕)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆