类似的问题Access ViewPager views from onCreate? 我创建了一个 ViewPager,可以在其中移动不同的布局。一种布局有一个按钮。我的问题是,如果用户单击此按钮,他将移动另一个页面。如何实现它。这是 viewpager 适配器类:
public class SwipeAdapter extends PagerAdapter {
private LayoutInflater mInflater;
private static int[] mLayouts = { R.layout.view_layout1,
R.layout.view_layout2, R.layout.view_layout3, R.layout.view_layout4 };
SwipeAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ViewGroup pageView= (ViewGroup) mInflater.inflate(mLayouts[position],
container, false);
container.addView(pageView);
getItemPosition(pageView);
return pageView;
}
/**
* @return the mCurrentposition
*/
@Override
public int getCount() {
return mLayouts.length;
}
@Override
public boolean isViewFromObject(View view, Object obj) {
return view == obj;
}
}