我在ListView Item中有一个ViewPager。在ListView滚动中,我想获得我在ViewPager中选择的上一页。
我试图将位置设置为
vPager.setTag(position)
但没有找到检索我的上一页的方法
这是我的ListView的getView()
public View getView(int position, View view, ViewGroup vGroup) {
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vRow=view;
final ContentHolder holder;
if(view==null){
holder=new ContentHolder();
vRow=inflater.inflate(R.layout.activity_swipe_view_pager, null);
holder.vPager=(ViewPager) vRow.findViewById(R.id.ui_pager);
holder.radiogrp=(RadioGroup) vRow.findViewById(R.id.ui_radiogroup);
int pageCount=integer.length;
addRadio=new AddRadioViewSwipe(context, pageCount);
addRadio.addRadio(holder.radiogrp);
try{
holder.radiogrp.getChildAt(0).setAlpha(1.0f);
}
catch(Exception e){
Log.d("loop", "error"+e);
}
vRow.setTag(holder);
}
else{
holder=(ContentHolder) vRow.getTag();
}
ViewPagerAdapter pagerAdpt=new ViewPagerAdapter(context, integer,R.layout.activity_viewpager_model);
holder.vPager.setAdapter(pagerAdpt);
holder.vPager.setOffscreenPageLimit(3);
holder.vPager.setTag(position);
holder.vPager.setPageMargin(-150);
holder.vPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
Log.d("pos", ""+position);
if(holder.vPager.isShown()){
}
for(int i=0;i<integer.length;i++){
holder.radiogrp.getChildAt(integer.length-(i+1)).setAlpha(0.5f);
}
holder.radiogrp.getChildAt(position).setAlpha(1.0f);
Log.d("pos", ""+position+"");
}
@Override
public void onPageScrolled(int position, float arg1, int arg2) {
Log.d("t1", ""+position);
}
@Override
public void onPageScrollStateChanged(int arg0) {
Log.d("t1...", ""+arg0);
}
});
return vRow;
}
答案 0 :(得分:0)
这对我有用:
Parcelable state=holder.vPager.onSaveInstanceState();
holder.vPager.setAdapter(pagerAdpt);
holder.vPager.onRestoreInstanceState(state);