Example usage for android.widget AbsListView setOnScrollListener

List of usage examples for android.widget AbsListView setOnScrollListener

Introduction

In this page you can find the example usage for android.widget AbsListView setOnScrollListener.

Prototype

public void setOnScrollListener(OnScrollListener l) 

Source Link

Document

Set the listener that will receive notifications every time the list scrolls.

Usage

From source file:com.nextgis.metroaccess.ui.view.StationExpandableListView.java

public void smoothScrollToPositionFromTop(final int position) {
    View child = getChildAtPosition(position);
    // There's no need to scroll if child is already at top or view is already scrolled to its end
    if ((child != null)
            && ((child.getTop() == 0) || ((child.getTop() > 0) && !ViewCompat.canScrollVertically(this, 1)))) {
        return;//from   ww  w  .j  a v  a 2 s . co m
    }

    setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(final AbsListView view, final int scrollState) {
            if (scrollState == SCROLL_STATE_IDLE) {
                view.setOnScrollListener(null);

                // Fix for scrolling bug
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        view.setSelection(position);
                    }
                });
            }
        }

        @Override
        public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount,
                final int totalItemCount) {
        }
    });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Perform scrolling to position
        new Handler().post(new Runnable() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void run() {
                smoothScrollToPositionFromTop(position, 0);
            }
        });
    }
}

From source file:com.cyanogenmod.eleven.ui.fragments.AlbumFragment.java

/**
 * Sets up various helpers for both the list and grid
 * //w w w.j a v a  2 s .co  m
 * @param list The list or grid
 */
private void initAbsListView(final AbsListView list) {
    // Release any references to the recycled Views
    list.setRecyclerListener(new RecycleHolder());
    // Show the albums and songs from the selected artist
    list.setOnItemClickListener(this);
    // To help make scrolling smooth
    list.setOnScrollListener(this);
}

From source file:com.andrew.apollo.ui.fragments.AlbumFragment.java

/**
 * Sets up various helpers for both the list and grid
 * //  w  ww .j  a v a 2s  .  c  om
 * @param list The list or grid
 */
private void initAbsListView(final AbsListView list) {
    // Release any references to the recycled Views
    list.setRecyclerListener(new RecycleHolder());
    // Listen for ContextMenus to be created
    list.setOnCreateContextMenuListener(this);
    // Show the albums and songs from the selected artist
    list.setOnItemClickListener(this);
    // To help make scrolling smooth
    list.setOnScrollListener(this);
}

From source file:com.andrew.apollo.ui.fragments.profile.ApolloFragment.java

/**
 * Sets up various helpers for both the list and grid
 *
 * @param list The list or grid//from w  ww  .j  av a 2  s. c  om
 */
private void initAbsListView(final AbsListView list) {
    // Release any references to the recycled Views
    list.setRecyclerListener(new RecycleHolder());
    // Listen for ContextMenus to be created
    list.setOnCreateContextMenuListener(this);
    // Show the albums and songs from the selected artist
    list.setOnItemClickListener(this);

    // To help make scrolling smooth
    if (mProfileTabCarousel != null) {
        list.setOnScrollListener(new VerticalScrollListener(null, mProfileTabCarousel, 0));
        // Remove the scrollbars and padding for the fast scroll
        list.setVerticalScrollBarEnabled(false);
        list.setFastScrollEnabled(false);
        list.setPadding(0, 0, 0, 0);
    }
}

From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java

private void addAutoLoadMoreListener() {
    if (!isDealAutoLoadMoreListenerDone) {
        if (contentView instanceof AbsListView) {
            AbsListView absListView = (AbsListView) contentView;
            onScrollListener = Utils.getScrollListener(absListView);
            absListView.setOnScrollListener(new AbsListView.OnScrollListener() {
                @Override//  ww  w.  j  a  v  a  2 s  . c om
                public void onScrollStateChanged(AbsListView view, int scrollState) {
                    if (onScrollListener != null) {
                        onScrollListener.onScrollStateChanged(view, scrollState);
                    }
                }

                @Override
                public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                        int totalItemCount) {
                    dealAutoLoadMore();
                    if (onScrollListener != null) {
                        onScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
                    }
                }
            });
        } else if (contentView instanceof RecyclerView) {
            ((RecyclerView) contentView).addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                    super.onScrollStateChanged(recyclerView, newState);
                }

                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    dealAutoLoadMore();
                }
            });
        }
        isDealAutoLoadMoreListenerDone = true;
    }
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

private Common setScrollListener() {
    AbsListView lv = (AbsListView) view;
    Common common = (Common) lv.getTag(Constants.TAG_SCROLL_LISTENER);
    if (common == null) {
        common = new Common();
        lv.setOnScrollListener(common);
        lv.setTag(Constants.TAG_SCROLL_LISTENER, common);
        AQUtility.debug("set scroll listenr");
    }//from  ww w  .j a v a  2s .c o  m
    return common;
}

From source file:github.daneren2005.dsub.fragments.SubsonicFragment.java

protected void setupScrollList(final AbsListView listView) {
    if (!context.isTouchscreen()) {
        refreshLayout.setEnabled(false);
    } else {/*from w w  w.jav  a  2s  . c  o  m*/
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                int topRowVerticalPosition = (listView.getChildCount() == 0) ? 0
                        : listView.getChildAt(0).getTop();
                refreshLayout
                        .setEnabled(topRowVerticalPosition >= 0 && listView.getFirstVisiblePosition() == 0);
            }
        });

        refreshLayout.setColorScheme(R.color.holo_blue_light, R.color.holo_orange_light,
                R.color.holo_green_light, R.color.holo_red_light);
    }
}

From source file:github.popeen.dsub.fragments.SubsonicFragment.java

protected void setupScrollList(final AbsListView listView) {
    if (!context.isTouchscreen()) {
        refreshLayout.setEnabled(false);
    } else {/*from w  ww.  ja va  2  s  . co m*/
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                int topRowVerticalPosition = (listView.getChildCount() == 0) ? 0
                        : listView.getChildAt(0).getTop();
                refreshLayout
                        .setEnabled(topRowVerticalPosition >= 0 && listView.getFirstVisiblePosition() == 0);
            }
        });

        refreshLayout.setColorSchemeResources(R.color.holo_blue_light, R.color.holo_orange_light,
                R.color.holo_green_light, R.color.holo_red_light);
    }
}

From source file:com.androidquery.AbstractAQuery.java

private Common setScrollListener() {

    AbsListView lv = (AbsListView) view;

    Common common = (Common) lv.getTag(AQuery.TAG_SCROLL_LISTENER);
    if (common == null) {
        common = new Common();
        lv.setOnScrollListener(common);/* w  w w.ja va 2  s .  c  om*/
        lv.setTag(AQuery.TAG_SCROLL_LISTENER, common);
        AQUtility.debug("set scroll listenr");
    }

    return common;
}

From source file:de.timroes.swipetodismiss.SwipeDismissList.java

/**
 * Constructs a new swipe-to-dismiss touch listener for the given list view.
 *
 * @param listView The list view whose items should be dismissable.
 * @param callback The callback to trigger when the user has indicated that
 * she would like to dismiss one or more list items.
 * @param mode The mode this list handles multiple undos.
 *///from  w  w  w. ja v  a 2  s  . c  o m
public SwipeDismissList(AbsListView listView, OnDismissCallback callback, UndoMode mode) {

    if (listView == null) {
        throw new IllegalArgumentException("listview must not be null.");
    }

    mHandler = new HideUndoPopupHandler(this);
    mListView = listView;
    mCallback = callback;
    mMode = mode;

    ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);

    mDensity = mListView.getResources().getDisplayMetrics().density;

    // -- Load undo popup --
    LayoutInflater inflater = (LayoutInflater) mListView.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.undo_popup, null);
    mUndoButton = (Button) v.findViewById(R.id.undo);
    mUndoButton.setOnClickListener(new UndoHandler());
    mUndoButton.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // If user tabs "undo" button, reset delay time to remove popup
            mDelayedMsgId++;
            return false;
        }
    });
    mUndoText = (TextView) v.findViewById(R.id.text);

    mUndoPopup = new PopupWindow(v);
    mUndoPopup.setAnimationStyle(R.style.fade_animation);
    // Get scren width in dp and set width respectively
    int xdensity = (int) (mListView.getContext().getResources().getDisplayMetrics().widthPixels / mDensity);
    if (xdensity < 300) {
        mUndoPopup.setWidth((int) (mDensity * 280));
    } else if (xdensity < 350) {
        mUndoPopup.setWidth((int) (mDensity * 300));
    } else if (xdensity < 500) {
        mUndoPopup.setWidth((int) (mDensity * 330));
    } else {
        mUndoPopup.setWidth((int) (mDensity * 450));
    }
    mUndoPopup.setHeight((int) (mDensity * 56));
    // -- END Load undo popu --

    listView.setOnTouchListener(this);
    listView.setOnScrollListener(this.makeScrollListener());
    mEnabled = true;

    switch (mode) {
    case SINGLE_UNDO:
        mUndoActions = new ArrayList<Undoable>(1);
        break;
    default:
        mUndoActions = new ArrayList<Undoable>(10);
        break;
    }

}