我正在使用 Fragment Pager Adapter 和 PagerView 创建滑动选项卡。但面临一些问题。
这是我的:-ViewPagerAdapter
它显示第一个片段并显示第二个片段对话框(在后台加载数据)。当我滑动到第二个片段时,它会加载第三个片段对话框并在后台加载数据。
public class ViewPagerAdapter extends FragmentPagerAdapter { private Context _context; public ViewPagerAdapter(Context context, FragmentManager fm) { super(fm); _context = context; } @Override public Fragment getItem(int position) { Fragment f = new Fragment(); switch (position) { case 0: f = ReservationTab.newInstance(_context); break; case 1: f = GalleryTab.newInstance(_context); break; case 2: f = VideoTab.newInstance(_context); break; } return f; } @Override public int getCount() { return 3; } }
并从这里访问:--
private void setUpView() {
_mViewPager = (ViewPager) findViewById(R.id.viewPager);
_adapter = new ViewPagerAdapter(getApplicationContext(),
getSupportFragmentManager());
_mViewPager.setAdapter(_adapter);
_mViewPager.setCurrentItem(0);
}
private void setTab() {
_mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int position) {
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
System.out.println("PRINT position-- " + position);
switch (position) {
case 0:
first_tab.setVisibility(View.VISIBLE);
second_tab.setVisibility(View.INVISIBLE);
third_tab.setVisibility(View.INVISIBLE);
break;
case 1:
first_tab.setVisibility(View.INVISIBLE);
second_tab.setVisibility(View.VISIBLE);
third_tab.setVisibility(View.INVISIBLE);
break;
case 2:
first_tab.setVisibility(View.INVISIBLE);
second_tab.setVisibility(View.INVISIBLE);
third_tab.setVisibility(View.VISIBLE);
break;
}
}
});
}
@Override
public void onTabChanged(String arg0) {
// TODO Auto-generated method stub
}