检查 android 列表项(Drawable)是否仍然可见

发布于 2024-09-25 07:05:50 字数 509 浏览 1 评论 0原文

假设我有一个带有 LinearLayout 的 ImageView 和 TextView 列表。 现在我使用简单的 ArrayAdapter 扩展,它获取 Strig[][] 作为双字符串数组的项目(每个条目包含 String[2],其中第一个字符串是图像的 uri,第二个字符串是文本。我重写 getView 来显示图像和文本,当然是回收视图:-)。 然而,由于图像加载,即使是从资源加载也可能很慢,所以我在异步任务中执行此操作,这意味着我加载了默认图像,并且我使用: startLoading (这是我的方法),它会占用 ImageView 和 Uri 并一次图像已准备好,将其放置在图像视图中。

然而有时,由于它是一个列表,如果图像尚未加载并且我正处于该过程的中间,因此值得停止加载,以防我正在加载图像的行不再可见。

由于视图被回收,我无法检查 ImageView 是否可见,因为它可能可见,但具有不同的 Drawable...有没有办法让我知道在某些时候我的行无效且不可见?有没有一种简单的方法或外壳我需要开始使用标志和标签模式以及类似的东西来发现我的行不再有效?

Let's assume i got a list of ImageView and TextView with LinearLayout.
Now i'm using simple ArrayAdapter extension that gets Strig[][] as items which is an array of double strings (each entry contains String[2] where the first string is a uri to the image and the second one is the text. i override getView to display the image and text , recyling views, of course :-).
However since image loading, even from resources may be slow, i'm doing it in an async task, that means that i have a default image loaded and i use: startLoading (it's my method) that stakes the ImageView and the Uri and once the image is ready it places it in the image view.

However sometimes, since it's a list if the image is not loaded yet and I'm in the middle of the process it's worth while stopping the loading, and that's in case that the line i'm loading image for is no longer visible.

Since the views are recycled i can't check if ImageView is visible since it may be visible but with a different Drawable... is there a way for me to know at some point that my line in invalidated and not visible ? is there a simple way or shell i need to start using flags and tag pattern and stuff like that to discover that my line is no longer valid ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚如初 2024-10-02 07:05:50

我所做的基于 ListView 管理其视图的方式。

由于 ListView 真正使用的视图集有限,并且可能通过 getView() 方法的 ConvertView 参数传递给我们的适配器,因此我实现了以下内容:

  • 我有一个 LinkedList 类成员,我在其中存储要存储的 Uris已加载。这些 Uris 在 AsyncTask 成员中使用以检索图片。
  • 在 getView() 中返回项目视图之前,我的适配器将项目图片的 Urin 放置在 View.setTag(Object) 中。
  • 当我重用convertView时,在重用其内容之前,我会获取之前使用View.getTag()链接到的Uri,并从挂起的Uris LinkedList中删除相应的元素。

What I do is based on how the ListView manages it's views.

As there is a limited set of Views really used by the ListView and that might be passed to our Adapter through the convertView argument of the getView() method, I implemented the following:

  • I have a LinkedList class member where I store the Uris to be loaded. These Uris are consumed in an AsyncTask member to retrieve the pics.
  • Before returning the item view in getView(), my Adapter places the Urin of the item pic in the View.setTag(Object).
  • When I reuse a convertView, before reusing it's content I get the Uri it was previously linked to using View.getTag() and remove the corresponding element from the pending Uris LinkedList.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文