Android Adapter getView Method: call super.getView or not?

三世轮回 提交于 2019-12-13 04:55:19

问题


I saw getView implementations that used convertView parameter directly:

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

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?


回答1:


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

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

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()




回答2:


the super.getView( position, convertView, parent ); is unsefull since the super does nothing.

getView belongs to the Adapter interface.

here you can find the code



来源:https://stackoverflow.com/questions/16689018/android-adapter-getview-method-call-super-getview-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!