类似问题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;
}
}