Android Open Source - BusTicketer Central Pager Adapter






From Project

Back to project page BusTicketer.

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 BusTicketer 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 bus.ticketer.adapters;
/*w w w  .j  a  va2  s.com*/
import java.util.ArrayList;

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;
import bus.ticketer.fragments.BuyTicketsFragment;
import bus.ticketer.fragments.ShowTicketsFragment;
import bus.ticketer.passenger.R;

public class CentralPagerAdapter extends FragmentStatePagerAdapter {

  private int nSwipes = 2;
  private ArrayList<Fragment> fragments = new ArrayList<Fragment>();
  
  public CentralPagerAdapter(FragmentManager fm) {
    super(fm);
  }

  @Override
  public Fragment getItem(int i) {
    Fragment fragment;
    
    fragment = i == 0 ? new ShowTicketsFragment() : new BuyTicketsFragment();
    
    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_show_tickets;
               break;
           case 1:
               resId = R.layout.fragment_buy_tickets;
               break;
           case 2:
               resId = R.layout.fragment_history_tickets;
               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

bus.ticketer.adapters.CentralPagerAdapter.java
bus.ticketer.adapters.DialogAdapter.java
bus.ticketer.adapters.SpinnerAdapter.java
bus.ticketer.connection.ConnectionRunnable.java
bus.ticketer.connection.ConnectionRunnable.java
bus.ticketer.connection.ConnectionRunnable.java
bus.ticketer.connection.ConnectionThread.java
bus.ticketer.connection.ConnectionThread.java
bus.ticketer.connection.ConnectionThread.java
bus.ticketer.filters.MonthInputFilter.java
bus.ticketer.fragments.BuyTicketsFragment.java
bus.ticketer.fragments.ShowTicketsFragment.java
bus.ticketer.inspector.BusInspector.java
bus.ticketer.inspector.MainActivity.java
bus.ticketer.inspector.ResultActivity.java
bus.ticketer.inspector.ScanActivity.java
bus.ticketer.listeners.BusTabListener.java
bus.ticketer.listeners.PurchaseListener.java
bus.ticketer.listeners.RadioGroupListener.java
bus.ticketer.listeners.SwipeListener.java
bus.ticketer.listeners.TicketPurchaseListener.java
bus.ticketer.listeners.ValidationListener.java
bus.ticketer.objects.Ticket.java
bus.ticketer.passenger.BeamActivity.java
bus.ticketer.passenger.BusTicketer.java
bus.ticketer.passenger.CentralActivity.java
bus.ticketer.passenger.MainActivity.java
bus.ticketer.runnable.BuyRunnable.java
bus.ticketer.runnable.ShowRunnable.java
bus.ticketer.runnable.TimerRunnable.java
bus.ticketer.runnable.TimerThread.java
bus.ticketer.utils.BusTimer.java
bus.ticketer.utils.BusUtils.java
bus.ticketer.utils.FileHandler.java
bus.ticketer.utils.FileWriter.java
bus.ticketer.utils.Method.java
bus.ticketer.utils.Method.java
bus.ticketer.utils.Method.java
bus.ticketer.utils.RESTFunction.java
bus.ticketer.utils.RESTFunction.java
bus.ticketer.utils.RESTFunction.java
bus.ticketer.utils.SpinnerAdapter.java
bus.ticketer.validation.MainActivity.java
bus.ticketer.validation.ResultActivity.java