How to get the image (its position) in focus in the image gallery?

I play with gallery widgets.

I would like to know how we can get the position of the image in focus in the gallery.

For example, having several photos in my gallery, if I touch my finger to the right, the images will come and go until they stop at one.

How can I get the position of this single image that is currently in focus?

I don’t know if I was clear enough if there is something you want me to add, feel free to. Thanks,

+4
source share
1 answer

Install OnItemSelectedListener in the gallery widget, override the corresponding method [I think the callback is called onItemSelected(...) ]. The position of the element in focus will be passed as an argument to this callback function.

Pseudocode:

 Gallery g = (Gallery) findViewById(R.id.gallery); //set Adapter with appropriate data model g.setOnItemSelectedListener(this); public void onItemSelected(AdapterView parent, View v, int position, long id) { //position is item having focus } 

Hope this helps ...

+7
source

Source: https://habr.com/ru/post/1309410/


All Articles