@Override public void setViewPager(ViewPager viewPager) { if (mViewPager == viewPager) { return; } if (mViewPager != null) { // Clear us from the old pager. mViewPager.setOnPageChangeListener(null); } if (viewPager.getAdapter() == null) { throw new IllegalStateException("ViewPager does not have adapter instance."); } mViewPager = viewPager; mViewPager.setOnPageChangeListener(this); invalidate(); post( new Runnable() { @Override public void run() { if (mFades) { post(mFadeRunnable); } } }); }
@Override public void setViewPager(ViewPager view) { if (mViewPager == view) return; if (mViewPager != null) { mViewPager.setOnPageChangeListener(null); } if (view.getAdapter() == null) throw new IllegalStateException("ViewPager does not have adapter instance."); mViewPager = view; mViewPager.setOnPageChangeListener(this); invalidate(); }
public void setViewPager(ViewPager paramViewPager) { if (f == paramViewPager) { return; } if (f != null) { f.setOnPageChangeListener(null); } if (paramViewPager.getAdapter() == null) { throw new IllegalStateException("ViewPager does not have adapter instance."); } f = paramViewPager; f.setOnPageChangeListener(this); invalidate(); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); pic = new int[] {R.drawable.revocw1, R.drawable.revocw2, R.drawable.revocw3, R.drawable.revocw4}; label_pic = new String[] {"Hijau", "Merah", "Biru", "Hitam"}; vp = (ViewPager) getActivity().findViewById(R.id.view_pager_detail); adapt = new Absolute_Revo_CW_Adapter(getActivity(), pic, label_pic); vp.setAdapter(adapt); vp.setCurrentItem(0); vp.setOnPageChangeListener( new OnPageChangeListener() { @Override public void onPageSelected(int arg0) {} @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int arg0) { isScrooled = true; } }); }
@Override public void doWithData(ArrayList<JsonElement> jsonElements) { AlbumPager.this.gallery = LoadIntoPager.this.gallery; images = new ArrayList<>(jsonElements); ViewPager p = (ViewPager) findViewById(R.id.images_horizontal); getSupportActionBar().setSubtitle(1 + "/" + images.size()); AlbumViewPager adapter = new AlbumViewPager(getSupportFragmentManager()); p.setAdapter(adapter); p.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) { getSupportActionBar().setSubtitle((position + 1) + "/" + images.size()); } @Override public void onPageSelected(int position) {} @Override public void onPageScrollStateChanged(int state) {} }); adapter.notifyDataSetChanged(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { init(container, savedInstanceState); setHasOptionsMenu(true); final View view = inflater.inflate(R.layout.fragment_books_pager, container, false); final Bundle extras = getArguments(); if (extras != null) { mBookPosition = extras.getInt(Keys.BOOK_POSITION); } mBookDetailPager = (ViewPager) view.findViewById(R.id.pager_books); mBookDetailPager.setOnPageChangeListener(this); mSlidingLayout = (SlidingUpPanelLayout) view.findViewById(R.id.sliding_layout); mSlidingLayout.setPanelSlideListener(this); mAdapter = new BookPageAdapter(getChildFragmentManager(), null); mBookDetailPager.setAdapter(mAdapter); if (savedInstanceState == null) { final ProfileFragment fragment = new ProfileFragment(); getChildFragmentManager() .beginTransaction() .replace(R.id.content_user_profile, fragment, FragmentTags.USER_PROFILE) .commit(); } else { mBookPosition = savedInstanceState.getInt(Keys.BOOK_POSITION); } loadBookSearchResults(); return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_container); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); actionBar = getActionBar(); mAdapter = new TabsAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); /** on swiping the viewpager make respective tab selected */ viewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int arg0) {} }); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void init(Context context) { // Disable clipping of children so non-selected pages are visible setClipChildren(false); // Child clipping doesn't work with hardware acceleration in Android 3.x/4.x // You need to set this value here if using hardware acceleration in an // application targeted at these releases. if (Build.VERSION.SDK_INT >= 11) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // 添加ViewPager mPager = new ViewPager(context); mPager.setId(R.id.pager); // If hardware acceleration is enabled, you should also remove // clipping on the pager for its children. mPager.setClipChildren(false); mPager.setPageMargin(pageMargin); mPager.setOnPageChangeListener(this); // Necessary or the pager will only have one extra page to show // make this at least however many pages you can see mPager.setOffscreenPageLimit(calcOffscreenPageLimit()); mPager.setLayoutParams( new FrameLayout.LayoutParams(pageWidth, pageHeight, Gravity.CENTER_HORIZONTAL)); this.addView(mPager); }
/** This method is used to initializeLayout. */ public void initializeLayout() { viewpager = (ViewPager) findViewById(R.id.hbdemo_viewpager); ViewPagerAdapter vpAdapter = new ViewPagerAdapter(getSupportFragmentManager()); viewpager.setAdapter(vpAdapter); viewpager.setOnPageChangeListener(new ViewPagerListener()); if (flag == 1) changePagerPage(0); }
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mView = inflater.inflate(R.layout.view_pager, null); showLeft = (Button) mView.findViewById(R.id.showLeft); showRight = (Button) mView.findViewById(R.id.showRight); mPager = (ViewPager) mView.findViewById(R.id.pager); PageFragment1 page1 = new PageFragment1(); PageFragment2 page2 = new PageFragment2(); pagerItemList.add(page1); pagerItemList.add(page2); mAdapter = new MyAdapter(getFragmentManager()); mPager.setAdapter(mAdapter); mPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { if (myPageChangeListener != null) myPageChangeListener.onPageSelected(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int position) {} }); return mView; }
@Override protected void onCreate(Bundle savedInstanceState) { Log.i(TAG, "setting selected id from intent"); setSelectedItemIDFromIntent(); ActiveUser activeUser = ((GiveOrTakeApplication) getApplication()).getActiveUser(); if (activeUser == null || activeUser.getUserID() == null) { Intent logoutIntent = new Intent(this, LoginActivity.class); logoutIntent.putExtra(LoginFragment.EXTRA_LOGIN_ACTION, LoginFragment.LOGOUT); logoutIntent.putExtra(MainActivity.EXTRA_ITEM_ID, getSelectedItemID()); startActivity(logoutIntent); finish(); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mViewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab( actionBar .newTab() .setText(mSectionsPagerAdapter.getPageTitle(i)) .setIcon(mSectionsPagerAdapter.getPageIcon(i)) .setTabListener(this)); } actionBar.selectTab(actionBar.getTabAt(DEFAULT_SELECTED_TAB)); Long itemID = getSelectedItemID(); if (itemID != null) { actionBar.selectTab(actionBar.getTabAt(FREE_ITEMS_TAB)); } }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_attention); mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); final ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(true); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { actionBar.addTab( actionBar .newTab() .setText(mAppSectionsPagerAdapter.getPageTitle(i)) .setTabListener(this)); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (findViewById(R.id.fragmentDetails) != null) { if (savedInstanceState == null) { DetailFragment detailFragment = new DetailFragment(); getSupportFragmentManager() .beginTransaction() .replace(R.id.fragmentDetails, detailFragment, DetailFragment.DETAILS_TAG) .commit(); } twoPane = true; } pager = (ViewPager) findViewById(R.id.pager); final ActionBar actionBar = getSupportActionBar(); assert actionBar != null; setActionBar(actionBar); FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager()); pager.setAdapter(adapter); pager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrollStateChanged(int state) {} }); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); pic = new int[] {R.drawable.cbr250rabsrk}; label_pic = new String[] {"Hitam"}; vp = (ViewPager) getActivity().findViewById(R.id.view_pager_detail); adapt = new CBR_250R_ABS_RE(getActivity(), pic, label_pic); vp.setAdapter(adapt); vp.setCurrentItem(0); vp.setOnPageChangeListener( new OnPageChangeListener() { @Override public void onPageScrollStateChanged(int arg0) { isScrooled = true; } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageSelected(int arg0) {} }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view == null) { view = inflater.inflate(R.layout.fragment_item, container, false); lv = (PullToRefreshListView) view.findViewById(R.id.news_lv); View header = inflater.inflate(R.layout.layout_news_lv_header, null); vp = (ViewPager) header.findViewById(R.id.news_header_vp); dd = (LinearLayout) header.findViewById(R.id.news_header_dd); vp.setOnPageChangeListener(pageChangeListener); lv.getRefreshableView().addHeaderView(header); lv.getRefreshableView().setCacheColorHint(Color.TRANSPARENT); lv.getRefreshableView().setSelector(new ColorDrawable(Color.TRANSPARENT)); adapter = new NewsAdapter(getActivity(), null); lv.getLoadingLayoutProxy(false, true).setPullLabel("上拉加载..."); lv.getLoadingLayoutProxy(false, true).setRefreshingLabel("正在加载..."); lv.getLoadingLayoutProxy(false, true).setReleaseLabel("松开加载更多..."); lv.setAdapter(adapter); lv.setOnRefreshListener(listener2); // 获取Activity传递过来的参数 Bundle mBundle = getArguments(); tid = mBundle.getString("tid"); loadNews(false); lv.setOnItemClickListener(itemClickListener); } ViewGroup parent = (ViewGroup) view.getParent(); if (null != parent) { parent.removeView(view); } return view; }
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.network_monitor_content); final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager); final FragmentManager fm = getSupportFragmentManager(); if (pager != null) { final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs); pagerTabs.addTabLabels( R.string.network_monitor_peer_list_title, R.string.network_monitor_block_list_title); final PagerAdapter pagerAdapter = new PagerAdapter(fm); pager.setAdapter(pagerAdapter); pager.setOnPageChangeListener(pagerTabs); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg_less_bright); peerListFragment = new PeerListFragment(); blockListFragment = new BlockListFragment(); } else { peerListFragment = (PeerListFragment) fm.findFragmentById(R.id.peer_list_fragment); blockListFragment = (BlockListFragment) fm.findFragmentById(R.id.block_list_fragment); } }
/** Set up spinner navigation with swiped pages */ private void setUpNavigation() { // Navigation spinner in toolbar for trainings selection LayoutInflater.from(mToolbar.getContext()).inflate(R.layout.navigation_spinner, mToolbar, true); mNavigationSpinner = (Spinner) mToolbar.findViewById(R.id.navigation_spinner); mNavigationSpinner.setOnItemSelectedListener(this); mNavigationSpinner.setSelection(mPosition); String[] from = new String[] {Trainings.EXERCISE}; int[] to = new int[] {R.id.title}; mNavigationAdapter = new NavigationAdapter( mToolbar.getContext(), R.layout.navigation_spinner_item, null, from, to, 0); mNavigationAdapter.setDropDownViewResource(R.layout.navigation_spinner_dropdown_item); mNavigationSpinner.setAdapter(mNavigationAdapter); // ViewPager for swipe navigation and animation on training select mViewPager.setOnPageChangeListener(this); mPagerAdapter = new TrainingPagerAdapter(getChildFragmentManager(), null); mViewPager.setAdapter(mPagerAdapter); Loader<Cursor> loader = getLoaderManager().getLoader(0); if (loader != null && !loader.isReset()) { getLoaderManager().restartLoader(0, null, this); } else { getLoaderManager().initLoader(0, null, this); } }
/** Setting the CarouselView with data */ private void setCarouselView() { // Getting the number of services discovered PAGES = ProfileScanningFragment.gattServiceData.size(); FIRST_PAGE = PAGES * LOOPS / 2; // Setting the adapter adapter = new CarouselPagerAdapter( getActivity(), ProfileControlFragment.this, getActivity().getSupportFragmentManager(), ProfileScanningFragment.gattServiceData); pager.setAdapter(adapter); pager.setOnPageChangeListener(adapter); // Set current item to the middle page so we can fling to both // directions left and right pager.setCurrentItem(FIRST_PAGE); // Necessary or the pager will only have one extra page to show // make this at least however many pages you can see pager.setOffscreenPageLimit(3); Toast.makeText( getActivity(), getResources().getString(R.string.toast_swipe_profiles), Toast.LENGTH_SHORT) .show(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); doBindService(); final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar.addTab( actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
/** Adds tabs below the action bar. */ private void addTabs() { viewPager = (ViewPager) findViewById(R.id.pager_main); actionBar = getActionBar(); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // temp fix, to make sure that PATHAlerts isn't refreshing all the time viewPager.setOffscreenPageLimit(4); // Adding Tabs for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this)); } viewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int arg0) {} }); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); viewPager = (ViewPager) getActivity().findViewById(R.id.pager); actionBar = getActivity().getActionBar(); mAdapter = new Course1Adapter(getActivity().getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setHomeButtonEnabled(true); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Add the tabs here for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this)); } viewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // on Page change, that particular page should be selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int position) {} }); }
@Override public void setViewPager(ViewPager view) { if (mViewPager == view) { return; } if (mViewPager != null) { mViewPager.setOnPageChangeListener(null); } final PagerAdapter adapter = view.getAdapter(); if (adapter == null) { throw new IllegalStateException("ViewPager does not have adapter instance."); } mViewPager = view; view.setOnPageChangeListener(this); notifyDataSetChanged(); }
private void initData() { mViewPager.setOnPageChangeListener( new OnPageChangeListener() { @Override public void onPageSelected(int position) { switch (position) { case 0: order_left_line.setVisibility(View.VISIBLE); order_right_line.setVisibility(View.INVISIBLE); break; case 1: order_left_line.setVisibility(View.INVISIBLE); order_right_line.setVisibility(View.VISIBLE); break; } } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int arg0) {} }); if (this.context != null) { MainActivity activity = (MainActivity) this.context; String storeName = activity.sessionManager.get("store_name"); order_title.setText(storeName); } }
@Override View getContentView(PagerAdapter pages) { FrameLayout result = new FrameLayout(helper.getHost()); master = buildListView(helper.getHost()); result.addView( master, new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); View listEmptyView = helper.buildListEmptyView(); result.addView( listEmptyView, new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER)); master.setEmptyView(listEmptyView); detail = buildViewPager(helper.getHost(), pages); detail.setOnPageChangeListener(this); showMaster(); result.addView( detail, new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); return (result); }
/** 图片循环 */ private void initViewPager() { ViewGroup.LayoutParams mViewPagerlayoutParams = mViewPager.getLayoutParams(); if (mViewPagerlayoutParams != null) { mViewPagerlayoutParams.width = Misc.getScreenDisplay(this)[0]; mViewPagerlayoutParams.height = (int) (mViewPagerlayoutParams.width); mViewPager.setLayoutParams(mViewPagerlayoutParams); } mViewPager.setAdapter(new ProductDetailPicAdapter2(this, product.getImgList())); mViewPager.setOnPageChangeListener(this); // 设置布局参数 LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int marginParam = Misc.dip2px(this, 10) / 2; llytPagerPoiner.removeAllViewsInLayout(); for (int i = 0; i < product.getImgList().size(); i++) { // 设置按钮属性 View item = new ImageView(this); item.setBackgroundResource(R.drawable.recommend_gallery); item.setTag(String.valueOf(i)); // item.setOnClickListener(parentActivity); params.setMargins(marginParam, 0, marginParam, 0); params.weight = 1; llytPagerPoiner.addView(item, params); } llytPagerPoiner.getChildAt(0).setBackgroundResource(R.drawable.recommend_gallery_select); }
@Override public void initView() { viewPager = (ViewPager) findViewById(R.id.vp_net_photos); btn_exit = (Button) findViewById(R.id.btn_net_photos_exit); btn_save = (Button) findViewById(R.id.btn_net_photos_save); txt_index = (TextView) findViewById(R.id.txt_net_photos_index); txt_index.setText(clickPosition + 1 + "/" + photos.length); fragments = new ArrayList<Fragment>(); for (int i = 0; i < photos.length; i++) { NetPhotoFragment fragment = new NetPhotoFragment(this, photos[i], handler); fragments.add(fragment); } CommonFPAdapter adapter = new CommonFPAdapter(getSupportFragmentManager(), fragments); viewPager.setAdapter(adapter); viewPager.setOnPageChangeListener( new OnPageChangeListener() { public void onPageSelected(int arg0) { txt_index.setText(arg0 + 1 + "/" + photos.length); } public void onPageScrolled(int arg0, float arg1, int arg2) {} public void onPageScrollStateChanged(int arg0) {} }); viewPager.setCurrentItem(clickPosition); MyOnClickListener listener = new MyOnClickListener(); btn_exit.setOnClickListener(listener); btn_save.setOnClickListener(listener); }
private void initAssessments() { // TODO Auto-generated method stub prefsHandler = new PrefsHandler(AssessmentType.this); vpAssessments = (ViewPager) activityContentView.findViewById(R.id.assessments_view_viewPager_assessment_types); getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); getActionBar().addTab(getActionBar().newTab().setText("Assignments").setTabListener(this)); getActionBar().addTab(getActionBar().newTab().setText("C.A.T's").setTabListener(this)); getActionBar().addTab(getActionBar().newTab().setText("End of Sem").setTabListener(this)); vpAssessments.setAdapter(new AssessmentsPagerAdapter(getSupportFragmentManager())); vpAssessments.setOnPageChangeListener(this); if (prefsHandler.isSeasonEnabled()) { switch (prefsHandler.getSeason()) { case 4: vpAssessments.setCurrentItem(0); break; case 5: vpAssessments.setCurrentItem(1); break; case 6: vpAssessments.setCurrentItem(2); break; default: vpAssessments.setCurrentItem(0); } } }
private void initComponent() { LayoutInflater inflater = getActivity().getLayoutInflater(); mMainView = inflater.inflate(R.layout.fragment_main, null, false); viewPager = (ViewPager) mMainView.findViewById(R.id.viewpager); fragmentList = new ArrayList<Fragment>(); fragmentList.add(new MyFragment(null)); fragmentList.add(new FindFragment()); fragmentList.add(new SearchFragment()); tabButton = new RadioButton[fragmentList.size()]; tabButton[0] = (RadioButton) mMainView.findViewById(R.id.tab_my); tabButton[1] = (RadioButton) mMainView.findViewById(R.id.tab_find); tabButton[2] = (RadioButton) mMainView.findViewById(R.id.tab_search); group = (RadioGroup) mMainView.findViewById(R.id.tab); group.setOnCheckedChangeListener(new TabOnCheckedChangeListener()); viewPager.setAdapter(new TabFragmentPagerAdapter(getFragmentManager())); viewPager.setCurrentItem(0); // 设置viewpager的缓存页面 viewPager.setOffscreenPageLimit(fragmentList.size()); viewPager.setOnPageChangeListener(new TabOnPageChangeListener()); // viewPager.setBackgroundResource(R.drawable.skin_def); setTabButtonBackground(TAB_INDEX); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // initialize the inflater mInflater = inflater; View rootView = mInflater.inflate(R.layout.app_ops_summary, container, false); mContentContainer = container; mRootView = rootView; mPageNames = getResources().getTextArray(R.array.app_ops_categories); mViewPager = (ViewPager) rootView.findViewById(R.id.pager); MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager()); mViewPager.setAdapter(adapter); mViewPager.setOnPageChangeListener(adapter); PagerTabStrip tabs = (PagerTabStrip) rootView.findViewById(R.id.tabs); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { tabs.setTabIndicatorColorResource(android.R.color.holo_blue_light); } else { final TypedValue val = new TypedValue(); getActivity().getTheme().resolveAttribute(android.R.attr.colorAccent, val, true); tabs.setTabIndicatorColor(val.data); } // We have to do this now because PreferenceFrameLayout looks at it // only when the view is added. if (container != null && "android.preference.PreferenceFrameLayout".equals(container.getClass().getName())) { new ObjectWrapper(rootView.getLayoutParams()).set("removeBorders", true); } return rootView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // fragments集合加数据 fragments = new ArrayList<Fragment>(); for (int i = 0; i < 5; i++) { // 新建一个带type的fragment对象 Fragment fragment = MyFragment.getInstance(ContentType.values()[i]); fragments.add(fragment); } mPager = (ViewPager) findViewById(R.id.viewpager_home); MyAdapter pagerAdapter = new MyAdapter(getSupportFragmentManager(), fragments); mPager.setAdapter(pagerAdapter); mPager.setOnPageChangeListener(this); // fragment_top = new TopFregment(); // fragment_cyclopedia = new CyclopediaFregment(); // fragment_consult = new ConsultFregment(); // fragment_manage = new ManageFregment(); // fragment_data = new DataFregment(); // 创建ActionbarTab 设置监听事件 intiActionTab(); }