Android按钮滚动条,android – ViewPager中的按钮滚动到特定页面

我的ViewPager里面的一个布局有一个按钮. “R.layout.add_site”.我想要点击按钮的选项,并滚动到我的具体页面.我已经有了滑动到特定页面的选项,但我想同时拥有这两个.

现在我确定有办法做到这一点,但由于某种原因,我无法理解.

你会看到我已经尝试了,但只是不知道要调用什么方法来使其滚动到所需的页面.哪个是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;

}

}

}

任何帮助是赞赏!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值