juan
juan

Reputation: 179

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

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?

Upvotes: 0

Views: 2535

Answers (2)

britzl
britzl

Reputation: 10242

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

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157467

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

Upvotes: 2

Related Questions