Skip to content

Latest commit

 

History

History
85 lines (57 loc) · 2.5 KB

event-listeners.md

File metadata and controls

85 lines (57 loc) · 2.5 KB

Event Listeners

You can add event listeners to catch events like:

  • image click event

  • long image click event

  • page change event

Click Listener

You can add on image click listener using GalleryBuilder (recommended approach):

.onImageClickListener(new ScrollGalleryView.OnImageClickListener() {
                    @Override
                    public void onClick(int position) {
                        Toast.makeText(MainActivity.this, "image position = " + position, Toast.LENGTH_SHORT).show();
                    }
                })

Or add event listener right to the ScrollGalleryView:

galleryView.addOnImageClickListener(new ScrollGalleryView.OnImageClickListener() {
            @Override
            public void onClick(int position) {
                
            }
        });

You should not add listeners directly to the ScrollGalleryView cause you can face with initialization bug. More details here.

Long Click Listener

Add long click listener with GalleryBuilder (recommended approach):

.onImageLongClickListener(new ScrollGalleryView.OnImageLongClickListener() {
                    @Override
                    public void onClick(int position) {
                        Toast.makeText(MainActivity.this, "image position = " + position, Toast.LENGTH_SHORT).show();
                    }
                })

Or add it to the ScrollGalleryView:

galleryView.addOnImageLongClickListener(new ScrollGalleryView.OnImageLongClickListener() {
            @Override
            public void onClick(int position) {
                
            }
        });

Page Change Listener

For now library supports only adding this listener directly to the ScrollGalleryView:

galleryView.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });