list = new ArrayList<android.support.v4.app.Fragment>(); list.add(new Fragment01()); list.add(new Fragment02()) ; viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public android.support.v4.app.Fragment getItem(int position) { return list.get(position); } @Override public int getCount() { return list.size(); } }); viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { switch (position){ case 0: group.check(R.id.but01); break; case 1: group.check(R.id.but02); break; default: break; } } @Override public void onPageScrollStateChanged(int state) { } }); group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { switch (i){ case R.id.but01: viewPager.setCurrentItem(0); break; case R.id.but02: viewPager.setCurrentItem(1); break; default: break; } } }); }
Fragment
最新推荐文章于 2023-09-12 16:54:54 发布