我在ViewPager中有三个页面,我想要实现的是当我滑动并选择一个新页面时,将使用新的变量值重新创建页面。
当我滑到下一页时,我想要以下页面:
现在发生的事情是,当我轻扫一次时,它会以3为增量的循环打印出arg0。
初始值:
private int zero = 0;
private int one = 1;
private int two = 2;
createViews方法:
public void createViews(){
FrameLayout v0 = (FrameLayout) inflater.inflate (R.layout.fragment_schema, null);
TextView t = (TextView) v0.findViewById(R.id.test);
t.setText("" + zero);
FrameLayout v1 = (FrameLayout) inflater.inflate (R.layout.fragment_schema, null);
TextView t1 = (TextView) v1.findViewById(R.id.test);
t1.setText("" + one);
FrameLayout v2 = (FrameLayout) inflater.inflate (R.layout.fragment_schema, null);
TextView t2 = (TextView) v2.findViewById(R.id.test);
t2.setText("" + two);
pagerAdapter.addView(v0, 0);
pagerAdapter.addView(v1, 1);
pagerAdapter.addView(v2, 2);
pagerAdapter.notifyDataSetChanged();
}
onPageSelected方法:
public void onPageSelected(int arg0) {
System.out.println(arg0);
if(arg0==0){
zero--;
one--;
two--;
}else if(arg0==2){
zero++;
one++;
two++;
}
createViews();
}