开发者

How to get which image (its position) is on focus in an Image Gallery?

开发者 https://www.devze.com 2022-12-30 02:00 出处:网络
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.

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开发者_StackOverflow中文版 there is anything you want me to add do not hesitate. Thank you,


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号