Android Open Source - Android-ParallaxHeaderViewPager Sample List Fragment






From Project

Back to project page Android-ParallaxHeaderViewPager.

License

The source code is released under:

Apache License

If you think the Android project Android-ParallaxHeaderViewPager 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.kmshack.newsstand;
/*from  w  ww. j a  va2 s. com*/
import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SampleListFragment extends ScrollTabHolderFragment implements OnScrollListener {

  private static final String ARG_POSITION = "position";

  private ListView mListView;
  private ArrayList<String> mListItems;

  private int mPosition;

  public static Fragment newInstance(int position) {
    SampleListFragment f = new SampleListFragment();
    Bundle b = new Bundle();
    b.putInt(ARG_POSITION, position);
    f.setArguments(b);
    return f;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPosition = getArguments().getInt(ARG_POSITION);

    mListItems = new ArrayList<String>();

    for (int i = 1; i <= 100; i++) {
      mListItems.add(i + ". item - currnet page: " + (mPosition + 1));
    }
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_list, null);

    mListView = (ListView) v.findViewById(R.id.listView);

    View placeHolderView = inflater.inflate(R.layout.view_header_placeholder, mListView, false);
    mListView.addHeaderView(placeHolderView);

    return v;
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mListView.setOnScrollListener(this);
    mListView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.list_item, android.R.id.text1, mListItems));
  }

  @Override
  public void adjustScroll(int scrollHeight) {
    if (scrollHeight == 0 && mListView.getFirstVisiblePosition() >= 1) {
      return;
    }

    mListView.setSelectionFromTop(1, scrollHeight);

  }

  @Override
  public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    if (mScrollTabHolder != null)
      mScrollTabHolder.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount, mPosition);
  }

  @Override
  public void onScrollStateChanged(AbsListView view, int scrollState) {
    // nothing
  }

}




Java Source Code List

com.astuetz.PagerSlidingTabStrip.java
com.flavienlaurent.notboringactionbar.AlphaForegroundColorSpan.java
com.flavienlaurent.notboringactionbar.KenBurnsSupportView.java
com.flavienlaurent.notboringactionbar.ParallaxImageView.java
com.kmshack.newsstand.MainActivity.java
com.kmshack.newsstand.SampleListFragment.java
com.kmshack.newsstand.ScrollTabHolderFragment.java
com.kmshack.newsstand.ScrollTabHolder.java