1

I have a Gallery object that scrolls from left to right and back again. However, I would like to make this Gallery circle back on itself, that way when I get to my last View, the very first one is next and I can just keep scrolling. Any ideas? Thanks.

Swifty McSwifterton
  • 2,637
  • 1
  • 30
  • 37

1 Answers1

4

Galleries use an Adapter to back the data that they display. You can create a custom adapter where getCount() returns Integer.MAX_VALUE and getView() does a modulos the position with the number of images you have. This way it always returns the appropriate image for a given position.

spatulamania
  • 6,613
  • 2
  • 30
  • 26
  • I implemented that like this: position = position % mImageIds.length; However, it only scrolls infinitely from left to right. Would you happen to know how to make it go infinitely both ways? Thanks very much for your help, by the way. – Swifty McSwifterton Oct 03 '11 at 00:49
  • Yes, I did. Do you know how to make it scroll infinitely in both directions, though? As it is it will only go to the right infinitely. I should have been more clear in my original question. – Swifty McSwifterton Oct 03 '11 at 00:56
  • 1
    you can use `setSelection(Integer.MAX_VALUE / 2)` to start in the middle. note that this isn't really an infinitely repeating list but it should be close enough from a user standpoint. – spatulamania Oct 03 '11 at 01:00