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

The following examples show how to use android.widget.AbsListView#getAdapter() . 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: ViewUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
/**
 * get AbsListView height according to every children
 *
 * @param view
 * @return
 */
public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
        return 0;
    }

    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View item = adapter.getView(i, null, view);
        if (item instanceof ViewGroup) {
            item.setLayoutParams(new LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        item.measure(0, 0);
        height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
}
 
Example 2
Source File: ScrollingPauseLoadManager.java    From sketch with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (AppConfig.INSTANCE.getBoolean(view.getContext(), AppConfig.Key.SCROLLING_PAUSE_LOAD) && view.getAdapter() != null) {
        ListAdapter listAdapter = view.getAdapter();
        if (listAdapter instanceof WrapperListAdapter) {
            listAdapter = ((WrapperListAdapter) listAdapter).getWrappedAdapter();
        }
        if (listAdapter instanceof BaseAdapter) {
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
                if (!sketch.getConfiguration().isPauseLoadEnabled()) {
                    sketch.getConfiguration().setPauseLoadEnabled(true);
                }
            } else if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
                if (sketch.getConfiguration().isPauseLoadEnabled()) {
                    sketch.getConfiguration().setPauseLoadEnabled(false);
                    ((BaseAdapter) listAdapter).notifyDataSetChanged();
                }
            }
        }
    }

    if (absListScrollListener != null) {
        absListScrollListener.onScrollStateChanged(view, scrollState);
    }
}
 
Example 3
Source File: AbsListScrollSize.java    From Paralloid with Apache License 2.0 6 votes vote down vote up
/**
     * This method is by no means accurate, and Will only work to any degree of accuracy if your list items
     * are the same height.
     * Otherwise it becomes vastly more difficult to calculate the correct height.
     *
     * @param listView listView to get height of, if no adapter is attached then nothing will happen.
     * @return 0 for failure.
     */
    public static int calculateApproximateHeight(AbsListView listView) {
        final ListAdapter adapter = listView.getAdapter();
        int onScreenHeight = 0, totalHeight = 0;
        final int totalCount = adapter.getCount();
        final int visibleCount = listView.getLastVisiblePosition() - listView.getFirstVisiblePosition();
        if (totalCount > 0) {
            View view;
            for (int i = 0; i < visibleCount; i++) {
//                final View view = adapter.getView(0, null, listView);
                view = listView.getChildAt(i);
//                view.measure(
//                        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
//                        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                onScreenHeight += view.getMeasuredHeight();
            }
            // Get the average on screen height, then multiply it up.
            totalHeight = (onScreenHeight / visibleCount) * totalCount;
            // Add the divider height.
            if (listView instanceof ListView) {
                totalHeight += ((ListView) listView).getDividerHeight() * (totalCount - 1);
            }
        }
        return totalHeight;
    }
 
Example 4
Source File: AbsListScrollSize.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
/**
     * This method is by no means accurate, and Will only work to any degree of accuracy if your list items
     * are the same height.
     * Otherwise it becomes vastly more difficult to calculate the correct height.
     *
     * @param listView listView to get height of, if no adapter is attached then nothing will happen.
     * @return 0 for failure.
     */
    public static int calculateApproximateHeight(AbsListView listView) {
        final ListAdapter adapter = listView.getAdapter();
        int onScreenHeight = 0, totalHeight = 0;
        final int totalCount = adapter.getCount();
        final int visibleCount = listView.getLastVisiblePosition() - listView.getFirstVisiblePosition();
        if (totalCount > 0) {
            View view;
            for (int i = 0; i < visibleCount; i++) {
//                final View view = adapter.getView(0, null, listView);
                view = listView.getChildAt(i);
//                view.measure(
//                        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
//                        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                onScreenHeight += view.getMeasuredHeight();
            }
            // Get the average on screen height, then multiply it up.
            totalHeight = (onScreenHeight / visibleCount) * totalCount;
            // Add the divider height.
            if (listView instanceof ListView) {
                totalHeight += ((ListView) listView).getDividerHeight() * (totalCount - 1);
            }
        }
        return totalHeight;
    }
 
Example 5
Source File: FolderFragment.java    From filemanager with MIT License 6 votes vote down vote up
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
		int visibleItemCount, int totalItemCount)
{		
	if (firstVisibleItem < this.topVisibleItem - DISTANCE_TO_HIDE_ACTIONBAR)
	{
		setActionbarVisibility(true);
		this.topVisibleItem = firstVisibleItem;
	}
	else if (firstVisibleItem > this.topVisibleItem + DISTANCE_TO_HIDE_ACTIONBAR)
	{
		setActionbarVisibility(false);
		this.topVisibleItem = firstVisibleItem;
	}
	
	ListAdapter adapter = view.getAdapter();
	if (adapter instanceof HeaderViewListAdapter)
	{
		HeaderViewListAdapter headerViewListAdapter = (HeaderViewListAdapter) adapter;
		if (headerViewListAdapter.getWrappedAdapter() instanceof FileCardAdapter)
		{
			int startPrefetch = firstVisibleItem + visibleItemCount-headerViewListAdapter.getHeadersCount();
			((FileCardAdapter) headerViewListAdapter.getWrappedAdapter()).prefetchImages(startPrefetch, visibleItemCount);
		}
	}
}
 
Example 6
Source File: ViewUtils.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
/**
 * get AbsListView height according to every children
 * 
 * @param view
 * @return
 */
public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
        return 0;
    }

    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View item = adapter.getView(i, null, view);
        if (item instanceof ViewGroup) {
            item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        item.measure(0, 0);
        height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
}
 
Example 7
Source File: SlidingLayout.java    From LLApp with Apache License 2.0 5 votes vote down vote up
/**
 * 判断View是否可以下拉
 * @return canChildScrollDown
 */
public boolean canChildScrollDown() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (mTargetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTargetView;
            return absListView.getChildCount() > 0 && absListView.getAdapter() != null
                    && (absListView.getLastVisiblePosition() < absListView.getAdapter().getCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1)
                    .getBottom() < absListView.getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTargetView, 1);
    }
}
 
Example 8
Source File: ScrollingUtil.java    From TwinklingRefreshLayout with Apache License 2.0 5 votes vote down vote up
public static void scrollToBottom(final AbsListView absListView) {
    if (absListView != null) {
        if (absListView.getAdapter() != null && absListView.getAdapter().getCount() > 0) {
            absListView.post(new Runnable() {
                @Override
                public void run() {
                    absListView.setSelection(absListView.getAdapter().getCount() - 1);
                }
            });
        }
    }
}
 
Example 9
Source File: BGARefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
public boolean shouldHandleAbsListViewLoadingMore(AbsListView absListView) {
    if (mIsLoadingMore || mCurrentRefreshStatus == RefreshStatus.REFRESHING || mLoadMoreFooterView == null || mDelegate == null || absListView == null ||  absListView.getAdapter() == null || absListView.getAdapter().getCount() == 0) {
        return false;
    }

    int lastChildBottom = 0;
    if (absListView.getChildCount() > 0) {
        // 如果AdapterView的子控件数量不为0,获取最后一个子控件的bottom
        lastChildBottom = absListView.getChildAt(absListView.getChildCount() - 1).getBottom();
    }
    return absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1 && lastChildBottom <= absListView.getMeasuredHeight();
}
 
Example 10
Source File: AbViewUtil.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static int getAbsListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace) {
    int totalHeight = 0;
    int w = MeasureSpec.makeMeasureSpec(0, 0);
    int h = MeasureSpec.makeMeasureSpec(0, 0);
    absListView.measure(w, h);
    ListAdapter mListAdapter = (ListAdapter) absListView.getAdapter();
    if (mListAdapter == null) {
        return 0;
    }
    int count = mListAdapter.getCount();
    View listItem;
    if (absListView instanceof ListView) {
        for (int i = 0; i < count; i++) {
            listItem = mListAdapter.getView(i, null, absListView);
            listItem.measure(w, h);
            totalHeight += listItem.getMeasuredHeight();
        }
        if (count == 0) {
            totalHeight = verticalSpace;
        } else {
            totalHeight += ((ListView) absListView).getDividerHeight() * (count - 1);
        }
    } else if (absListView instanceof GridView) {
        int remain = count % lineNumber;
        if (remain > 0) {
            remain = 1;
        }
        if (mListAdapter.getCount() == 0) {
            totalHeight = verticalSpace;
        } else {
            listItem = mListAdapter.getView(0, null, absListView);
            listItem.measure(w, h);
            int line = (count / lineNumber) + remain;
            totalHeight = (listItem.getMeasuredHeight() * line) + ((line - 1) * verticalSpace);
        }
    }
    return totalHeight;
}
 
Example 11
Source File: SlidingLayout.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 判断View是否可以下拉
 *
 * @return canChildScrollDown
 */
public boolean canChildScrollDown() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (mTargetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTargetView;
            return absListView.getChildCount() > 0 && absListView.getAdapter() != null
                    && (absListView.getLastVisiblePosition() < absListView.getAdapter().getCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1)
                    .getBottom() < absListView.getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTargetView, 1);
    }
}
 
Example 12
Source File: DPullRefreshLayout.java    From Pas with Apache License 2.0 5 votes vote down vote up
/**
 * ListView滚动底部是否
 * @param absListView
 * @return
 */
public boolean shouldHandleAbsListViewLoadingMore(AbsListView absListView) {
    if (mIsLoadingMore || mCurrentRefreshStatus == RefreshStatus.REFRESHING ||
            mLoadMoreFooterView == null || mDelegate == null || absListView == null
            || absListView.getAdapter() == null || absListView.getAdapter().getCount() == 0) {
        return false;
    }

    int lastChildBottom = 0;
    if (absListView.getChildCount() > 0) {
        // 如果AdapterView的子控件数量不为0,获取最后一个子控件的bottom
        lastChildBottom = absListView.getChildAt(absListView.getChildCount() - 1).getBottom();
    }
    return absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1 && lastChildBottom <= absListView.getMeasuredHeight();
}
 
Example 13
Source File: ScrollingUtil.java    From Pas with Apache License 2.0 5 votes vote down vote up
public static void scrollToBottom(final AbsListView absListView) {
    if (absListView != null) {
        if (absListView.getAdapter() != null && absListView.getAdapter().getCount() > 0) {
            absListView.post(new Runnable() {
                @Override
                public void run() {
                    absListView.setSelection(absListView.getAdapter().getCount() - 1);
                }
            });
        }
    }
}
 
Example 14
Source File: ScrollingUtil.java    From TwinklingRefreshLayout with Apache License 2.0 5 votes vote down vote up
public static boolean isAbsListViewToBottom(AbsListView absListView) {
    if (absListView != null && absListView.getAdapter() != null && absListView.getChildCount() > 0 && absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1) {
        View lastChild = absListView.getChildAt(absListView.getChildCount() - 1);

        return lastChild.getBottom() <= absListView.getMeasuredHeight();
    }
    return false;
}
 
Example 15
Source File: ScrollingUtil.java    From AgentWebX5 with Apache License 2.0 5 votes vote down vote up
public static void scrollToBottom(final AbsListView absListView) {
    if (absListView != null) {
        if (absListView.getAdapter() != null && absListView.getAdapter().getCount() > 0) {
            absListView.post(new Runnable() {
                @Override
                public void run() {
                    absListView.setSelection(absListView.getAdapter().getCount() - 1);
                }
            });
        }
    }
}
 
Example 16
Source File: ListViewFeeds.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
@Override
public
void onScrollStateChanged(AbsListView view, int scrollState)
{
    FeedsActivity activity = (FeedsActivity) view.getContext();

    if(SCROLL_STATE_TOUCH_SCROLL == scrollState || SCROLL_STATE_IDLE == scrollState)
    {
        Adapter adapter = view.getAdapter();
        int first = view.getFirstVisiblePosition();
        int last = view.getLastVisiblePosition();

        for(int i = 0; last - first >= i; i++)
        {
            View viewItem = view.getChildAt(i);

            if(null != viewItem && viewItem.isShown() && 0 <= viewItem.getTop())
            {
                FeedItem item = (FeedItem) adapter.getItem(first + i);
                activity.readItem(item.m_time);
            }
        }
    }
    if(SCROLL_STATE_IDLE == scrollState)
    {
        AsyncNavigationAdapter.run(activity);
    }
}
 
Example 17
Source File: ScrollingUtil.java    From AgentWebX5 with Apache License 2.0 5 votes vote down vote up
public static boolean isAbsListViewToBottom(AbsListView absListView) {
    if (absListView != null && absListView.getAdapter() != null && absListView.getChildCount() > 0 && absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1) {
        View lastChild = absListView.getChildAt(absListView.getChildCount() - 1);

        return lastChild.getBottom() <= absListView.getMeasuredHeight();
    }
    return false;
}
 
Example 18
Source File: SlidingLayout.java    From stynico with MIT License 5 votes vote down vote up
/**
 * 判断View是否可以下拉
 * @return canChildScrollDown
 */
public boolean canChildScrollDown() {
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (mTargetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTargetView;
            return absListView.getChildCount() > 0 && absListView.getAdapter() != null
                    && (absListView.getLastVisiblePosition() < absListView.getAdapter().getCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1)
                    .getBottom() < absListView.getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTargetView, 1);
    }
}