Java tutorial
/* * Copyright 2014 Nicholas Liu * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ca.zadrox.dota2esportticker.ui; import android.app.Fragment; import android.app.FragmentManager; import android.content.res.Resources; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import ca.zadrox.dota2esportticker.R; import ca.zadrox.dota2esportticker.ui.widget.SlidingTabLayout; /** * Created by Acco on 11/25/2014. */ public class TeamActivity extends BaseActivity { private static final String TAG = TeamActivity.class.getSimpleName(); public static int TEAM_FAV_LOADER_ID = 0; public static int TEAM_TOP_LOADER_ID = 1; ViewPager mViewPager = null; TeamPagerAdapter mTeamPagerAdapter = null; SlidingTabLayout mSlidingTabLayout = null; public TeamActivity() { } @Override protected int getSelfNavDrawerItem() { return NAVDRAWER_ITEM_TEAMS; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_team); mViewPager = (ViewPager) findViewById(R.id.view_pager); mTeamPagerAdapter = new TeamPagerAdapter(getFragmentManager()); mViewPager.setAdapter(mTeamPagerAdapter); mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs); mSlidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1); Resources res = getResources(); mSlidingTabLayout.setSelectedIndicatorColors(res.getColor(R.color.tab_selected_strip)); mSlidingTabLayout.setDistributeEvenly(true); mSlidingTabLayout.setViewPager(mViewPager); } private class TeamPagerAdapter extends FragmentPagerAdapter { public TeamPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { Fragment fragment; if (position == 0) { fragment = new TeamFavouriteFragment(); } else if (position == 1) { fragment = new TeamTopFragment(); } else { return null; } return fragment; } @Override public int getCount() { return 2; } @Override public CharSequence getPageTitle(int position) { switch (position) { case 0: return getString(R.string.team_favourites); case 1: return getString(R.string.team_top50); } return super.getPageTitle(position); } } }