CQM*_*CQM 28 android arraylist pager android-viewpager
我想得到我的PagerAdapter的可见视图的当前位置
我没有看到一个明显的功能getPosition()
,我想要一个.
我想在那个位置向它的arraylist添加一个对象,但我需要先知道它
Jon*_*ona 48
你会用:
int position = mViewPager.getCurrentItem()
Run Code Online (Sandbox Code Playgroud)
phi*_*ipp 23
我有这个问题,无法得到这个getCurrentItem()
方法.
我最终得到了来自ViewPager
而不是来自的位置PageAdapter
.该onPageSelected(int currentPage)
梅索德越来越当前显示的页面.
//custom PageAdapter implementation
mAdapter = new AwesomePagerAdapter();
//Our custom view pager that extends from ViewPager
mPager = (CustomViewPager) findViewById(R.id.preview_gallery);
mPager.setAdapter(mAdapter);
// get the item that we should be showing from the intent
mCurrentPage = extra.getInt("currentIndex");
// show the item the user picked
mPager.setCurrentItem(mCurrentPage);
// listen for page changes so we can track the current index
mPager.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageScrollStateChanged(int arg0) {
}
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
public void onPageSelected(int currentPage) {
//currentPage is the position that is currently displayed.
}
});
Run Code Online (Sandbox Code Playgroud)
在PageAdaper
我这样做不起作用,因为我想预加载不可见的图像.instantiateItem(View collection, int position)
PageAdapter` 传递的位置是初始化的下一个项目的位置.这与显示的项目无关.
归档时间: |
|
查看次数: |
35233 次 |
最近记录: |