我是编程的初学者,目前有点迷失。
我按照教程在我的应用中实现了滑动功能。它允许用户通过设置ScreenSlidePagerAdapter
类来在两个片段之间滑动。
以下代码与ScreenSlidePagerAdapter
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_incentive_timer);
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
@Override
public void onBackPressed() {
if (mPager.getCurrentItem() == 0) {
super.onBackPressed();
} else {
mPager.setCurrentItem(mPager.getCurrentItem() - 1);
}
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return NUM_PAGES;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
switch (position) {
case 0:
timerWindowReference = (TimerWindow) createdFragment;
break;
case 1:
incentiveWindowReference = (SettingsWindow) createdFragment;
break;
}
return createdFragment;
}
}
我的问题:
我有一个按钮和onClick
方法。如何在那里禁用和重新启用此Slider功能?