开发者

getFirstVisiblePosition() returns wrong value in Gallery View

I have a Gallery view created with a SimpleAdapter that extends BaseAdapter. It contains more items than what it can fit in the screen.

So I'm using Gallery.getFirstVisiblePosition() and Gallery.getLastVisiblePosition() to get the first and last visible position. But these functions doesn't always return the correct values especially after setting the selected position by calling mGallery.setSelection() followed by a SimpleAdapter.notifyDataChanged() call. Most of the time it getFirstVisiblePosition() returns 0 even if the first element is not visible.

Also note that the no. of visible items in Gallery is different in portrait and landscape mode. The value returned by getFirstVisiblePosition() look correct in landscape but is returned wrong in portrai开发者_StackOverflow社区t mode.

Anyone has any thoughts/ideas?

Thanks!


The first visible position will be updated only after a layout. You cannot call notifyDatasetChanged() and right away get the first visible position, you must wait for the next layout pass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜