Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the position of the current image displayed in Gallery

in my application , i have a gallery of pictures,

but i want to detect the position of the current image displayed ,

For example : when i launch my acvitivity, the position is 0, but when i scroll in my gallery,i want to get The position of the Current image displayed ,

i have tried OnFocusChanged , OnItemClicked , but that works only if i click on an item of my gallery

Any ideas ! :(

like image 997
Houcine Avatar asked May 13 '11 15:05

Houcine


3 Answers

gal.setOnItemSelectedListener(new OnItemSelectedListener(){
            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int position, long id) {
            //Do something with position
            }
};

You get this callback every time a new item in the gallery gets put in the center, So be careful not to do anything to work intensive because if the user scrolls fast you are going to get a callback for each item they pass.

like image 130
FoamyGuy Avatar answered Oct 24 '22 14:10

FoamyGuy


To eliminate the events during the fling, add this in addition to the setOnItemSelectedListener() call:

gal.setCallbackDuringFling(false);
like image 9
jsmith Avatar answered Oct 24 '22 14:10

jsmith


Use Gallery.getSelectedItemPosition()

like image 7
OcuS Avatar answered Oct 24 '22 12:10

OcuS