質問

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);
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top