当调用 ArrayAdapter 中的 getView() 时 [英] When getView() in ArrayAdapter is called

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

问题描述

在android中为ListView创建自定义adapter时,我看到我必须创建一个扩展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.

所有这些都可以,但我想知道调用方法和执行的顺序.即在代码的哪个点调用 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 docs -Adapter 对象充当 AdapterView(例如您的案例中的 ListView)和该视图的基础数据之间的桥梁.Adapter 提供对数据项的访问,还负责为数据集中的每个项创建一个视图.

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.

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

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