java - ListView 适配器中 `convertView` 的用途是什么?

标签 java android

在android中,我通常使用MyAdapter extends ArrayAdapter来为ListView创建 View ,结果,我不得不重写函数

public View getView(int position, View convertView, ViewGroup parent) {
    // somecode here
}

但是,我不知道 convertViewparent 到底是做什么的!有人有建议吗?更详细,更多帮助!谢谢!

最佳答案

从文档中,

convertView - The old view to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view.

换句话说,此参数严格用于提高 Adapter 的性能。当 ListView 使用 AdapterView 填充其行时,适配器使用 View 填充每个列表项> 通过在每一行上调用 getView() 对象。适配器使用 convertView 作为回收不再使用的旧 View 对象的一种方式。通过这种方式,ListView 可以向适配器发送不再显示的旧的“回收” View 对象,而不是在适配器每次想要显示新列表项时实例化一个全新的对象。这就是 convertView 参数的用途。

关于java - ListView 适配器中 `convertView` 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10560624/

相关文章:

javascript - Primefaces 7executeScript() 不在 ajax 请求中调用 javascript 函数

android - 引用错误 : Can't find variable: Permissions and ReferenceError: Can't find variable: ImagePicker

java - 从维基百科信息框获取具体信息

java - Hibernate Criteria API 与 JPQL

java - plattysoft粒子系统Java

Android OnClickListener 没有触发单独布局上的按钮

android - 如何在 <include/> 标签内链接 subview ?

android - 对 Android 中的 BLE 定向广告 (ADV_DIRECT_IND) 使用react

java - java 十进制到二进制的转换

java - JSP过滤非法url直接访问