Android: Programmatically move between images in Gallery widget

Posted by bdls on Stack Overflow See other posts from Stack Overflow or by bdls
Published on 2010-04-28T17:01:27Z Indexed on 2010/04/28 17:03 UTC
Read the original article Hit count: 940

Filed under:
|
|
|
|

I'd like to programmatically move between images in the Gallery widget, with animation.

I can change the currently displaying image using the setSelection(int position) method, however that does not animate. Then there's setSelection(int position, bool animate) but the extra boolean on the end there doesn't appear to do anything.

In the source of Gallery it appears that it can handle DPAD key-presses, so a work-around I thought of was to fake the key-presses. Eg.

dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT))

However I can't get this working for some reason. Anyone tried this?

I notice three of the widget's methods I'd love to use moveNext(), movePrevious() and scrollToChild() are all private and unusable.

Does anyone know how I might be able to do this?

© Stack Overflow or respective owner

Related posts about android

Related posts about widget