Java Code Examples for android.widget.AdapterView#getChildCount()

The following examples show how to use android.widget.AdapterView#getChildCount() . 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: MDRootLayout.java    From talk-android with MIT License 6 votes vote down vote up
private static boolean canAdapterViewScroll(AdapterView lv) {
    /* Force it to layout it's children */
    if (lv.getLastVisiblePosition() == -1)
        return false;

    /* We can scroll if the first or last item is not visible */
    boolean firstItemVisible = lv.getFirstVisiblePosition() == 0;
    boolean lastItemVisible = lv.getLastVisiblePosition() == lv.getCount() - 1;

    if (firstItemVisible && lastItemVisible && lv.getChildCount() > 0) {
        /* Or the first item's top is above or own top */
        if (lv.getChildAt(0).getTop() < lv.getPaddingTop())
            return true;
        /* or the last item's bottom is beyond our own bottom */
        return lv.getChildAt(lv.getChildCount() - 1).getBottom() >
                lv.getHeight() - lv.getPaddingBottom();
    }

    return true;
}
 
Example 2
Source File: AbsRefreshLayout.java    From NestRefreshLayout with MIT License 5 votes vote down vote up
private boolean canListScroll(int direction) {
    AdapterView<?> absListView = (AdapterView<?>) mTargetView;
    final int itemCount = absListView.getCount();
    final int childCount = absListView.getChildCount();
    final int firstPosition = absListView.getFirstVisiblePosition();
    final int lastPosition = firstPosition + childCount;

    if (itemCount == 0) {
        return false;
    }
    if (direction > 0) {
        // Are we already showing the entire last item?
        if (lastPosition >= itemCount) {
            final View lastView = absListView.getChildAt(childCount - 1);
            if (lastView != null
                    && lastView.getBottom() >= mTargetView.getHeight()) {
                return false;
            }
        }
    } else if (direction < 0) {
        // Are we already showing the entire first item?
        if (firstPosition <= 0) {
            final View firstView = absListView.getChildAt(0);
            if (firstView != null && firstView.getTop() >= 0) {
                return false;
            }
        }
    }
    return true;
}
 
Example 3
Source File: OverviewFragment.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
     if (parent.getChildCount() > 0) {
         ((TextView) parent.getChildAt(0)).setTextColor(Color.GRAY);

         OpenScale openScale = OpenScale.getInstance();

         List<ScaleUser> scaleUserList = openScale.getScaleUserList();
         ScaleUser scaleUser = scaleUserList.get(position);

         openScale.selectScaleUser(scaleUser.getId());
         updateOnView(openScale.getScaleMeasurementList());
     }
}