由网友(心至此ㄨ伤至极べ)分享简介:我知道与画廊插件,我能够使用getSelectedItemPosition();检索当前位置,但它似乎并不ViewPager都有。I know with the Gallery widget I was able to use getSelectedItemPosition(); to retrieve the cu...
我知道与画廊插件,我能够使用getSelectedItemPosition();检索当前位置,但它似乎并不ViewPager都有。
I know with the Gallery widget I was able to use getSelectedItemPosition(); to retrieve the current position, however it doesnt seem ViewPager has that.
我知道我可以设置一个监听和检索的位置时,页面切换。但我想当前视图位置。
I know I can setup a listener and retrieve the position when the page is switched. But I want the current view position.
推荐答案
创建一个监听器,并在你的viewpager设置:
Create a listener and set it on your viewpager:
/**
* Get the current view position from the ViewPager by
* extending SimpleOnPageChangeListener class and adding your method
*/
public class DetailOnPageChangeListener extends ViewPager.SimpleOnPageChangeListener {
private int currentPage;
@Override
public void onPageSelected(int position) {
currentPage = position;
}
public final int getCurrentPage() {
return currentPage;
}
}
相关推荐
最新文章