VEINHORN / ScrollGalleryView

:bridge_at_night: Android image gallery with bottom scroll view
MIT License
531 stars 157 forks source link

Set long click listener on images #70

Closed blackchineykh closed 5 years ago

blackchineykh commented 6 years ago

Hi, I would like to set a long click event listener on images. Is there a way I can access the imageview to set a long click listener and get the path, bitmap or index of the selected image?

VEINHORN commented 5 years ago

@blackchineykh Hi! Starting from version 1.2.6 you can add event listeners on images like here:

galleryView = ScrollGalleryView
                .from((ScrollGalleryView) findViewById(R.id.scroll_gallery_view))
                .settings(
                        GallerySettings
                                .from(getSupportFragmentManager())
                                .thumbnailSize(100)
                                .enableZoom(true)
                                .build()
                )
                .onImageClickListener(new ScrollGalleryView.OnImageClickListener() {
                    @Override
                    public void onClick(int position) {
                        Toast.makeText(MainActivity.this, "image position = " + position, Toast.LENGTH_SHORT).show();
                    }
                })
                .onImageLongClickListener(new ScrollGalleryView.OnImageLongClickListener() {
                    @Override
                    public void onClick(int position) {
                        Toast.makeText(MainActivity.this, "image position = " + position, Toast.LENGTH_SHORT).show();
                    }
                })
                .add(images(
                        "http://pirate-islands.com/wp-content/uploads/2018/07/07_Dom-Fernando-II_01-636x310.jpg",
                        "http://povodu.ru/wp-content/uploads/2016/04/pochemu-korabl-derzitsa-na-vode.jpg"
                ))
                .add(video("http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4", R.mipmap.default_video))
                .build();

This listeners now provide access to the current image position. You can also add listeners right to the ScrollGalleryView, but it's not recommended for now, more details here.