views:

100

answers:

2

Hi all,

I am playing around with the Gallery widget.

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

For example having several pictures in my gallery, if I tap my finger to the right, pictures will come and go until it stop to one.

How one can get the position of this one picture that is currently on focus ?

I don't know if I was clear enough, if there is anything you want me to add do not hesitate. Thank you,

+2  A: 

Set an OnItemSelectedListener on the Gallery Widget, override appropriate method [I think the callback is named onItemSelected(...)]. The position of item in focus would be passed as argument to this callback function.

Pseudo code:

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 that helps...

Samuh
Thank you very much ! It works !
Spredzy
A: 

After a bit of tweaking, worked for me as well, thanks.

andy_spoo