Get the position of the current image displayed in Gallery

社会主义新天地 提交于 2019-12-06 21:00:04

问题


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 ! :(


回答1:


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.




回答2:


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

gal.setCallbackDuringFling(false);



回答3:


Use Gallery.getSelectedItemPosition()



来源:https://stackoverflow.com/questions/5994181/get-the-position-of-the-current-image-displayed-in-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!