Question

I have a ListView. Naturally I pass an adapter to it, say mDogAdapter. My ListView also implements setOnItemClickListener.

So here is my question: in the context of getting an item from the adapter, what is the difference between these two?

Dog dog =(Dog) parent.getItemAtPosition(position);
Dog dog = mDogAdapter.getItem(position);
Was it helpful?

Solution

There's no difference.

The AdapterView's getItemAtPosition() method will call getItem() on the adapter in its implementation.

It's up to you to decide which makes more sense. If it's possible that you may use a different adapter at some point, you should consider using the AdapterView's getItemAtPosition() method -- let the AdapterView deal with getting the correct data from its Adapter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top