Android Open Source - Android-ParallaxHeaderViewPager Sample List Fragment

From Project

Back to project page Android-ParallaxHeaderViewPager.


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.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);
    return f;

  public void onCreate(Bundle 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));

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

    mListView = (ListView) v.findViewById(;

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

    return v;

  public void onActivityCreated(Bundle savedInstanceState) {

    mListView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.list_item,, mListItems));

  public void adjustScroll(int scrollHeight) {
    if (scrollHeight == 0 && mListView.getFirstVisiblePosition() >= 1) {

    mListView.setSelectionFromTop(1, scrollHeight);


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

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


Java Source Code List