Android Open Source - sloop Data Collection Pager Adapter






From Project

Back to project page sloop.

License

The source code is released under:

NON-LICENSE The Sloop data-browser source code is hereby released into the Public Domain. The original author, David Megginson, Megginson Technologies Ltd., and Acclar Open Ltd. provide no warranty:...

If you think the Android project sloop 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.megginson.sloop.ui;
/* w ww  .j  av  a 2 s  .  c  om*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.megginson.sloop.model.DataCollection;

/**
 * Pager adapter for a data collection.
 * 
 * The page includes a {@link DataRecordFilter} that can limit the number of
 * terms visible. The {@link #getCount()} method returns the number of items
 * that satisfy the filter, while the {@link #getUnfilteredCount()} method
 * returns the total size of the collection.
 * 
 * @author David Megginson
 */
public class DataCollectionPagerAdapter extends FragmentStatePagerAdapter {

  private DataCollection mDataCollection;

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

  /**
   * Get the data collection to be displayed.
   * 
   * @return the data collection, or null if application has not yet set one.
   */
  public DataCollection getDataCollection() {
    return mDataCollection;
  }

  /**
   * Set the underlying data collection.
   * 
   * @param dataCollection
   *            the data collection (should not be null).
   */
  public void setDataCollection(DataCollection dataCollection) {
    if (dataCollection != null) {
      mDataCollection = dataCollection;
    }
    notifyDataSetChanged();
  }

  @Override
  public Fragment getItem(int position) {
    DataRecordFragment fragment = new DataRecordFragment();
    Bundle args = new Bundle();
    args.putParcelable("dataRecord", mDataCollection.getFilteredRecords().get(position));
    fragment.setArguments(args);
    return fragment;
  }

  @Override
  public int getCount() {
    if (mDataCollection == null) {
      return 0;
    } else {
      return mDataCollection.getFilteredRecords().size();
    }
  }

  @Override
  public CharSequence getPageTitle(int position) {
    return "Record #" + (position + 1);
  }

  @Override
  public int getItemPosition(Object object) {
    return mDataCollection.getFilteredRecords().indexOf(object);
  }

}




Java Source Code List

com.megginson.sloop.activities.ActivitiesUtil.java
com.megginson.sloop.activities.AddressActionProvider.java
com.megginson.sloop.activities.BookmarkEditActivity.java
com.megginson.sloop.activities.BookmarkListActivity.java
com.megginson.sloop.activities.InfoBarFragment.java
com.megginson.sloop.activities.MainActivity.java
com.megginson.sloop.activities.MainDisplayFragment.java
com.megginson.sloop.activities.TextFilterFragment.java
com.megginson.sloop.activities.package-info.java
com.megginson.sloop.model.Bookmark.java
com.megginson.sloop.model.DataCollection.java
com.megginson.sloop.model.DataEntry.java
com.megginson.sloop.model.DataRecord.java
com.megginson.sloop.model.Util.java
com.megginson.sloop.model.ValueFilter.java
com.megginson.sloop.model.impl.ContainsStringFilter.java
com.megginson.sloop.model.impl.DataCollectionIO.java
com.megginson.sloop.model.impl.DataCollectionImpl.java
com.megginson.sloop.model.impl.DataEntryImpl.java
com.megginson.sloop.model.impl.DataRecordImpl.java
com.megginson.sloop.model.impl.EqualsStringFilter.java
com.megginson.sloop.model.impl.package-info.java
com.megginson.sloop.model.package-info.java
com.megginson.sloop.ui.BookmarkListAdapter.java
com.megginson.sloop.ui.DataCollectionLoader.java
com.megginson.sloop.ui.DataCollectionPagerAdapter.java
com.megginson.sloop.ui.DataCollectionResult.java
com.megginson.sloop.ui.DataRecordFragment.java
com.megginson.sloop.ui.DataRecordListAdapter.java
com.megginson.sloop.ui.package-info.java