Android Adapter getView方法:是否调用super.getView? [英] Android Adapter getView Method: call super.getView or not?

查看:142
本文介绍了Android Adapter getView方法:是否调用super.getView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了直接使用convertView参数的getView实现:

I saw getView implementations that used convertView parameter directly:

if(convertView!=null)
    ...
return convertView

另一个实现调用super.getView:

Another implementations call super.getView:

View view = super.getView( position, convertView, parent );
if(view!=null)
    ...
return view

我的问题是,什么是正确的方法?

My question is, What is the right method?

推荐答案

我想您是在谈论

I guess you are talking about Adapter.getView(). Which adapter are you extending?

大多数适配器本身没有getView()的实现,并希望您在自己放大视图之前检查convertView是否为null.

Most adapters have no implementation of getView() themselves and expect that you check if convertView is null before inflating a view one yourself.

我说大多数适配器,因为有例外.如果从第三方-lib继承适配器的子类,则该适配器实际上可能提供getView()的实现并处理视图回收.在那种情况下,您确实应该调用超类.

I say most adapters since there are exceptions. If you sub-class an Adapter from a third party -lib the adapter might actually provide an implementation of getView() and handle the view recycling. In that case you really should call the super-class.

此外,如果您查看

Also, if you take a look at the code for CursorAdapter it actually has an implementation of getView()

这篇关于Android Adapter getView方法:是否调用super.getView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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