在android中,我通常使用MyAdapter extends ArrayAdapter
来为ListView
创建 View ,结果,我不得不重写函数
public View getView(int position, View convertView, ViewGroup parent) {
// somecode here
}
但是,我不知道 convertView
和 parent
到底是做什么的!有人有建议吗?更详细,更多帮助!谢谢!
最佳答案
从文档中,
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
使用 Adapter
用 View
填充其行时,适配器使用 View
填充每个列表项> 通过在每一行上调用 getView()
对象。适配器使用 convertView
作为回收不再使用的旧 View
对象的一种方式。通过这种方式,ListView
可以向适配器发送不再显示的旧的“回收” View 对象,而不是在适配器每次想要显示新列表项时实例化一个全新的对象。这就是 convertView
参数的用途。
关于java - ListView 适配器中 `convertView` 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10560624/