Java Code Examples for android.widget.AbsListView#getCount()

The following examples show how to use android.widget.AbsListView#getCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlideBottomPanel.java    From pius1 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Copy From AbsListView (API Level >= 19)
 * @param absListView AbsListView
 * @param direction Negative to check scrolling up, positive to check
 *                  scrolling down.
 * @return true if the list can be scrolled in the specified direction,
 *         false otherwise
 */
private boolean absListViewCanScrollList(AbsListView absListView,int direction) {
    final int childCount = absListView.getChildCount();
    if (childCount == 0) {
        return false;
    }
    final int firstPosition = absListView.getFirstVisiblePosition();
    if (direction > 0) {//can scroll down
        final int lastBottom = absListView.getChildAt(childCount - 1).getBottom();
        final int lastPosition = firstPosition + childCount;
        return lastPosition < absListView.getCount() || lastBottom > absListView.getHeight() - absListView.getPaddingTop();
    } else {//can scroll  up
        final int firstTop = absListView.getChildAt(0).getTop();
        return firstPosition > 0 || firstTop < absListView.getPaddingTop();
    }
}
 
Example 2
Source File: AutoLoadMoreListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
	switch (scrollState) {
       case OnScrollListener.SCROLL_STATE_IDLE:
	    //Log.v(TAG, "已经停止:SCROLL_STATE_IDLE" + "-->" + view.getCount());
	    Context context = view.getContext();
	    SheJiaoMaoApplication sheJiaoMao = (SheJiaoMaoApplication) context.getApplicationContext();
	    if (view.getLastVisiblePosition() == view.getCount() - 1
	    	&& sheJiaoMao.isAutoLoadMore()) {
	    	view.getChildAt(view.getChildCount() - 1).performClick();
	    }
	    break;
       case OnScrollListener.SCROLL_STATE_FLING:
	    //Log.v(TAG, "开始滚动:SCROLL_STATE_FLING");
	    break;
	case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
	   //Log.v(TAG, "正在滚动:SCROLL_STATE_TOUCH_SCROLL");
	   break;
    }
}
 
Example 3
Source File: TBListView.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
                     int visibleItemCount, int totalItemCount) {
    mFirstVisibleItem = firstVisibleItem;
    if (view.getFirstVisiblePosition() == 1) {
        mIsTop = true;
        // 滑动到顶部
    } else if (onLoadMoreListener != null && view.getLastVisiblePosition() == view.getCount() - 1) {
        mIsBottom = true;
        onLoadMoreListener.onLoadMore();
        // 滑动到底部
    } else {
        mIsTop = false;
        mIsBottom = false;
    }
}
 
Example 4
Source File: SwipyRefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
public boolean canChildScrollDown() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            try {
                if (absListView.getCount() > 0) {
                    if (absListView.getLastVisiblePosition() + 1 == absListView.getCount()) {
                        int lastIndex = absListView.getLastVisiblePosition() - absListView.getFirstVisiblePosition();
                        return absListView.getChildAt(lastIndex).getBottom() == absListView.getPaddingBottom();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        } else {
            return true;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
}
 
Example 5
Source File: DiySwipeRefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
public boolean canChildScrollDown() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
    		View lastChild = absListView.getChildAt(absListView.getChildCount() - 1);
    		if (lastChild != null) {
    			return (absListView.getLastVisiblePosition() == (absListView.getCount() - 1))
    					&& lastChild.getBottom() > absListView.getPaddingBottom();
    		}
    		else
    		{
    			return false;
    		}
        } else {
            return mTarget.getHeight() - mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
}
 
Example 6
Source File: ViewCompat.java    From SmartSwipe with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the items in the list can be scrolled in a certain direction.
 *
 * @param listView listView
 * @param direction Negative to check scrolling up, positive to check
 *            scrolling down.
 * @return true if the list can be scrolled in the specified direction,
 *         false otherwise.
 */
public static boolean canListViewScrollVertical(AbsListView listView, int direction) {
    if (Build.VERSION.SDK_INT >= 19) {
        // Call the framework version directly
        return listView.canScrollList(direction);
    } else {
        // provide backport on earlier versions
        final int childCount = listView.getChildCount();
        if (childCount == 0) {
            return false;
        }

        final int firstPosition = listView.getFirstVisiblePosition();
        if (direction > 0) {
            final int lastBottom = listView.getChildAt(childCount - 1).getBottom();
            final int lastPosition = firstPosition + childCount;
            return lastPosition < listView.getCount()
                    || (lastBottom > listView.getHeight() - listView.getListPaddingBottom());
        } else {
            final int firstTop = listView.getChildAt(0).getTop();
            return firstPosition > 0 || firstTop < listView.getListPaddingTop();
        }
    }
}
 
Example 7
Source File: Util.java    From dynamiclistview with MIT License 6 votes vote down vote up
public static int getItemIndexAtLocation(AbsListView listView, int y) {
	int index = 0;

	if (listView.getCount() <= 0) 
		return index;

	int k = listView.getFirstVisiblePosition();

	for(int i = k ; i <= listView.getLastVisiblePosition() ; i++) {
		View view = listView.getChildAt(i - k);
		if (y > view.getTop() && y < view.getBottom() ) {
			return index = i;
		}
	}

	return 0;
}
 
Example 8
Source File: ViewPagerDelegate.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
@Override
public
boolean isReadyForPull(View view, float x, float y)
{
    boolean ready = false;

  /* First we check whether we're scrolled to the top of current page. */
    if(null != s_fragmentFeeds)
    {
        AbsListView absListView = getCurrentTagListView();

        if(0 == absListView.getCount())
        {
            ready = true;
        }
        else if(0 == absListView.getFirstVisiblePosition())
        {
            View firstVisibleChild = absListView.getChildAt(0);
            ready = null != firstVisibleChild && 0 <= firstVisibleChild.getTop();
        }

        if(ready && absListView.isFastScrollEnabled() && absListView.isFastScrollAlwaysVisible())
        {
            switch(absListView.getVerticalScrollbarPosition())
            {
                case View.SCROLLBAR_POSITION_LEFT:
                    return x > absListView.getVerticalScrollbarWidth();
                case View.SCROLLBAR_POSITION_RIGHT:
                    return x < absListView.getRight() - absListView.getVerticalScrollbarWidth();
            }
        }
    }
    return ready;
}
 
Example 9
Source File: AuthenticatorActivity.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the position of the one and only checked item in the provided list in multiple selection
 * mode.
 *
 * @return {@code 0}-based position.
 * @throws IllegalStateException if the list is not in multiple selection mode, or if the number
 *     of checked items is not {@code 1}.
 */
@TargetApi(11)
private static int getMultiSelectListSingleCheckedItemPosition(AbsListView list) {
  Preconditions.checkState(list.getCheckedItemCount() == 1);
  SparseBooleanArray checkedItemPositions = list.getCheckedItemPositions();
  Preconditions.checkState(checkedItemPositions != null);
  for (int i = 0, len = list.getCount(); i < len; i++) {
    boolean itemChecked = checkedItemPositions.get(i);
    if (itemChecked) {
      return i;
    }
  }

  throw new IllegalStateException("No items checked");
}
 
Example 10
Source File: AbsListViewDelegate.java    From Bitocle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isReadyForPull(View view, final float x, final float y) {
    boolean ready = false;

    // First we check whether we're scrolled to the top
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        ready = true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        ready = firstVisibleChild != null && firstVisibleChild.getTop() >= absListView.getPaddingTop();
    }

    // Then we have to check whether the fas scroller is enabled, and check we're not starting
    // the gesture from the scroller
    if (ready && absListView.isFastScrollEnabled() && isFastScrollAlwaysVisible(absListView)) {
        switch (getVerticalScrollbarPosition(absListView)) {
            case View.SCROLLBAR_POSITION_RIGHT:
                ready = x < absListView.getRight() - absListView.getVerticalScrollbarWidth();
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                ready = x > absListView.getVerticalScrollbarWidth();
                break;
        }
    }

    return ready;
}
 
Example 11
Source File: AbsListViewDelegate.java    From endpoints-codelab-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isScrolledToTop(View view) {
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        return true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        return firstVisibleChild != null && firstVisibleChild.getTop() >= 0;
    }
    return false;
}
 
Example 12
Source File: HandyListView.java    From WifiChat with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
		int visibleItemCount, int totalItemCount) {
	mFirstVisibleItem = firstVisibleItem;
	if (view.getFirstVisiblePosition() == 1) {
		mIsTop = true;
	} else if (view.getLastVisiblePosition() == view.getCount() - 1) {
		mIsBottom = true;
	} else {
		mIsTop = false;
		mIsBottom = false;
	}
}
 
Example 13
Source File: Util.java    From dynamiclistview with MIT License 5 votes vote down vote up
public static boolean reachedListBottom(AbsListView listView) {
	boolean flag = true;
	if (listView.getChildCount() != 0) {
		int i = listView.getLastVisiblePosition();
		int j = listView.getCount();
		int k = listView.getHeight();
		int l = listView.getChildAt(-1 + listView.getChildCount()).getBottom();
		if (i != j - 1 || l > k) {
			flag = false;
		}
	}
	return flag;
}
 
Example 14
Source File: AbsListViewDelegate.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public boolean isReadyForPull(View view, final float x, final float y) {
    boolean ready = false;

    // First we check whether we're scrolled to the top
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        ready = true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        ready = firstVisibleChild != null && firstVisibleChild.getTop() >= 0;
    }

    // Then we have to check whether the fas scroller is enabled, and check we're not starting
    // the gesture from the scroller
    if (ready && absListView.isFastScrollEnabled() && isFastScrollAlwaysVisible(absListView)) {
        switch (getVerticalScrollbarPosition(absListView)) {
            case View.SCROLLBAR_POSITION_RIGHT:
                ready = x < absListView.getRight() - absListView.getVerticalScrollbarWidth();
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                ready = x > absListView.getVerticalScrollbarWidth();
                break;
        }
    }

    return ready;
}
 
Example 15
Source File: ConversationFragment.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private static boolean scrolledToBottom(AbsListView listView) {
    final int count = listView.getCount();
    if (count == 0) {
        return true;
    } else if (listView.getLastVisiblePosition() == count - 1) {
        final View lastChild = listView.getChildAt(listView.getChildCount() - 1);
        return lastChild != null && lastChild.getBottom() <= listView.getHeight();
    } else {
        return false;
    }
}
 
Example 16
Source File: AbsListViewDelegate.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isScrolledToTop(View view) {
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        return true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        return firstVisibleChild != null && firstVisibleChild.getTop() >= 0;
    }
    return false;
}
 
Example 17
Source File: GridViewHandler.java    From CommonPullToRefresh with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && view.getLastVisiblePosition() + 1 == view.getCount()) {// 如果滚动到最后一行
        if (onScrollBottomListener != null) {
            onScrollBottomListener.onScorllBootom();
        }
    }
}
 
Example 18
Source File: ListViewHandler.java    From CommonPullToRefresh with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrollStateChanged(AbsListView listView, int scrollState) {
    if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && listView.getLastVisiblePosition() + 1 == listView.getCount()) {// 如果滚动到最后一行
        if (onScrollBottomListener != null) {
            onScrollBottomListener.onScorllBootom();
        }
    }
}
 
Example 19
Source File: DialogRootView.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Returns, whether a specific list view is scrolled to the bottom, or not.
 *
 * @param scrollView The list view as an instance of the class {@link AbsListView}. The list view may not
 *                   be null
 * @return True, if the given list view is scrolled to the bottom, false otherwise
 */
private boolean isListViewScrolledToBottom(@NonNull final AbsListView scrollView) {
    if (scrollView.getCount() > 0 && scrollView.getChildCount() > 0) {
        if (scrollView.getLastVisiblePosition() == scrollView.getCount() - 1) {
            View child = scrollView.getChildAt(scrollView.getChildCount() - 1);
            return child == null || child.getBottom() <= scrollView.getHeight();
        }
    } else {
        return true;
    }

    return false;
}
 
Example 20
Source File: MyRobot.java    From wakao-app with MIT License 5 votes vote down vote up
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
	listview.onScrollStateChanged(view, scrollState);
	// 当不滚动时
	if (scrollState == SCROLL_STATE_IDLE) {
		// 判断滚动到底部
		if (!IS_LOADING
				&& view.getLastVisiblePosition() == (view.getCount() - 1)) {
			Log.e("TAG", "loading。。。");
			IS_LOADING = true;
			getMore();
		}
	}
}