开发者

Gallery Position After scrolling

开发者 https://www.devze.com 2023-01-15 06:00 出处:网络
I have a gallery with 7 images. How can I get the positi开发者_StackOverflow社区on when stop the scrolling of a Gallery?For reference you can handle the setOnItemSelectedListenerof the Galley componen

I have a gallery with 7 images. How can I get the positi开发者_StackOverflow社区on when stop the scrolling of a Gallery?


For reference you can handle the setOnItemSelectedListenerof the Galley component to do this.

    // Gallery On Item Selected
    mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {

        // On Item Selected
        public void onItemSelected(CustomAdapterView<?> parent, View view,
                int position, long id) {

            // Do some custom action here!

        }
        //>

        // On Nothing Selected
        public void onNothingSelected(CustomAdapterView<?> parent) {
            // TODO Auto-generated method stub

        }
        //>
    });
    //-->


Are you using an Adapter with the Gallery? If so, then AdapterView has a getSelectedItemPosition() function that returns an int.

You can subclass the ImageAdapter class and add a function that returns a private int which is always updated to the index of the last 'clicked' image; thus giving you the position of the current image.

0

精彩评论

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

关注公众号