Android Open Source - ShareManager Main Pager Adapter






From Project

Back to project page ShareManager.

License

The source code is released under:

Copyright (c) 2013, Nelspike All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Red...

If you think the Android project ShareManager 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 share.manager.adapters;
//from   ww w . ja  va2 s.c o m
import java.util.ArrayList;

import share.manager.fragments.*;
import share.manager.stock.R;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;

public class MainPagerAdapter extends FragmentStatePagerAdapter {

  private int nSwipes = 3;
  private ArrayList<Fragment> fragments = new ArrayList<Fragment>();

  public MainPagerAdapter(FragmentManager fm) {
    super(fm);
  }

  @Override
  public Fragment getItem(int i) {
    Fragment fragment = null;

    fragment = i == 0 ? new MineFragment() : (i == 1 ? new SharesFragment()
        : new PortfolioFragment());

    fragments.add(fragment);
    return fragment;
  }

  @Override
  public int getCount() {
    return nSwipes;
  }

  @Override
  public Object instantiateItem(View collection, int position) {
    LayoutInflater inflater = (LayoutInflater) collection.getContext()
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    int resId = 0;
    switch (position) {
      case 0:
        resId = R.layout.fragment_mine;
        break;
      case 1:
        resId = R.layout.fragment_shares;
        break;
      case 2:
        resId = R.layout.fragment_portfolio;
        break;
    }

    View view = inflater.inflate(resId, null);
    ((ViewPager) collection).addView(view, 0);
    return view;
  }

  @Override
  public void destroyItem(View collection, int position, Object view) {
    fragments.remove(position);
    ((ViewPager) collection).removeViewAt(position);
  }

  @Override
  public Parcelable saveState() {
    return null;
  }

}




Java Source Code List

share.manager.adapters.CompanyAdapter.java
share.manager.adapters.DialogAdapter.java
share.manager.adapters.MainPagerAdapter.java
share.manager.adapters.SharesAdapter.java
share.manager.connection.ConnectionRunnable.java
share.manager.connection.ConnectionThread.java
share.manager.fragments.MineFragment.java
share.manager.fragments.PortfolioFragment.java
share.manager.fragments.SharesFragment.java
share.manager.listeners.ShareTabListener.java
share.manager.listeners.SwipeListener.java
share.manager.stock.CompanyActivity.java
share.manager.stock.MainActivity.java
share.manager.stock.ResultsActivity.java
share.manager.stock.SettingsActivity.java
share.manager.stock.ShareManager.java
share.manager.utils.CompanyGraphicsBuilder.java
share.manager.utils.FileHandler.java
share.manager.utils.GraphType.java
share.manager.utils.RESTFunction.java
share.manager.utils.ShareUtils.java
share.manager.utils.SharesGraphicsBuilder.java