ViewPager中的button滚动到特定页面

我的ViewPager中的一个布局有一个button。 “R.layout.add_site”。 我想要按下button的选项,并滚动到我的具体页面。 我已经可以select滑动到特定的页面,但我想要两个。

现在我确信有办法做到这一点,但由于某种原因,我无法弄清楚。

你会看到我已经做了一个尝试,但只是不知道要调用什么方法,使其滚动到所需的页面。 这是R.layout.main。

这是我的代码。

public class fieldsActivity extends Activity { Button addSiteButton; Button cancelButton; Button signInButton; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // to create a custom title bar for activity window requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.fields); // use custom layout title bar getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.topbar); Pager adapter = new Pager(); ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager); mPager.setAdapter(adapter); mPager.setCurrentItem(1); addSiteButton = (Button) findViewById(R.id.addSiteButton); addSiteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Don't know what method to call!? } }); cancelButton = (Button) findViewById(R.id.cancel_button); signInButton = (Button) findViewById(R.id.sign_in_button); } private class Pager extends PagerAdapter { public int getCount() { return 3; } @Override public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); int resId = 0; switch (position) { case 0: resId = R.layout.field01; break; case 1: resId = R.layout.add_site; break; case 2: resId = R.layout.main; break; } View view = inflater.inflate(resId, null); ((ViewPager) collection).addView(view, 0); return view; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } } } 

任何帮助表示赞赏!

Solutions Collecting From Web of "ViewPager中的button滚动到特定页面"