当getView()的ArrayAdapter被称为 [英] When getView() in ArrayAdapter is called

查看:114
本文介绍了当getView()的ArrayAdapter被称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建自定义的适配器的ListView 在Android中,我看到,我要创建一个类的扩展 ArrayAdapter 类,并实现了 getView(..)方法。

When creating a customized adapter for ListView in android, I see that I have to create a class the extends ArrayAdapter class and implements the getView(..) method.

所有这一切是美好的,但我想知道调用方法和执行的顺序。也就是在这点$ C C $的 getView()被调用?

All of that is OK, but I want to know the sequence of calling methods and executing. i.e. in which point of code the getView() is being called ?

推荐答案

从Android电子文档 - 一个适配器对象作为一个AdapterView(如ListView的你的情况),以及显示视图基本数据之间的桥梁。适配器提供访问的数据项和还负责制造视图在数据组中的每个项。

From android docs - An Adapter object acts as a bridge between an AdapterView (such as ListView in your case) and the underlying data for that view. The Adapter provides access to the data items and is also responsible for making a View for each item in the data set.

所以,当在ListView需要显示数据的一个特定行,它请求相关联的转接器,以提供相应于该在该位置通过getView数据()方法的图。每当视图需要更新在屏幕上,这可能会发生(例如,在创建过程中/滚动等)。

So, whenever the ListView needs to display a particular row of data, it requests the associated adapter to provide the view corresponding to that the data at that position through getView() method. This may occur whenever the view needs to be updated on screen (eg. during creation/scroll etc.).

作为一个应用程序开发人员,您不用担心究竟在这一点上getView()被调用,只要你提供一个具体的getView()在你的适配器实现。确认方法是有效的(缩略图等应该在后台线程加载)以获得最佳性能。

As an app developer, you need not worry about exactly at which point getView() is being called as long as you provide a concrete getView() implementation in your adapter. Make sure the method is efficient (thumbnails etc should be loaded in a background thread) for optimum performance.

这篇关于当getView()的ArrayAdapter被称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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