Android Open Source - ScienceQuiz Home Pager Adapter






From Project

Back to project page ScienceQuiz.

License

The source code is released under:

GNU General Public License

If you think the Android project ScienceQuiz listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.finger.sciencequiz;
/*from  w ww.  j a  v a  2s. c om*/
import java.util.Locale;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.content.Context;
import com.finger.sciencequiz.R;

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class HomePagerAdapter extends FragmentPagerAdapter
{
    private Context Context;

    public HomePagerAdapter (FragmentManager fm, Context context)
    {
  super (fm);
  Context = context;
    }

    @Override
    public Fragment getItem (int position)
    {
  // getItem is called to instantiate the fragment for the given page.
  // Return a Fragment with the page number as its lone argument.
  Fragment fragment = null;

  switch (position)
  {
  case 0:
      fragment = new RunningGamesHomeFragment ();
      break;
  case 1:
      fragment = new StartHomeFragment ();
      break;
  case 2:
      fragment = new FriendsHomeFragment ();
      break;
  case 3:
      fragment = new ProfileHomeFragment ();
      break;
  }

  return fragment;
    }

    @Override
    public int getCount ()
    {
  // Show 4 total pages.
  return 4;
    }

    @Override
    public CharSequence getPageTitle (int position)
    {
  Locale l = Locale.getDefault ();
  switch (position)
  {
  case 0:
      return Context.getString (R.string.running_games).toUpperCase (l);
  case 1:
      return Context.getString (R.string.start).toUpperCase (l);
  case 2:
      return Context.getString (R.string.friends).toUpperCase (l);
  case 3:
      return Context.getString (R.string.profile).toUpperCase (l);
  }
  return null;
    }
}




Java Source Code List

com.finger.sciencequiz.AboutActivity.java
com.finger.sciencequiz.ConfigReader.java
com.finger.sciencequiz.FriendsHomeFragment.java
com.finger.sciencequiz.GalleryViewPager.java
com.finger.sciencequiz.GameActivity.java
com.finger.sciencequiz.GameTypeSelectActivity.java
com.finger.sciencequiz.HistoryActivity.java
com.finger.sciencequiz.HomePagerAdapter.java
com.finger.sciencequiz.ImageAdapter.java
com.finger.sciencequiz.LobbyActivity.java
com.finger.sciencequiz.MainActivity.java
com.finger.sciencequiz.NavigationDrawerFragment.java
com.finger.sciencequiz.NewGameActivity.java
com.finger.sciencequiz.ProfileHomeFragment.java
com.finger.sciencequiz.RotationTextView.java
com.finger.sciencequiz.RunningGamesHomeFragment.java
com.finger.sciencequiz.SettingsActivity.java
com.finger.sciencequiz.StartHomeFragment.java