问题
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