Search in sources :

Example 66 with ListAdapter

use of android.widget.ListAdapter in project glitch-hq-android by tinyspeck.

the class ListViewUtil method getListViewHeightBasedOnChildren.

public static int getListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return -1;
    }
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        Log.i("measure", " i: " + i + " size: " + listItem.getMeasuredHeight());
        totalHeight += listItem.getMeasuredHeight();
    }
    return totalHeight;
}
Also used : View(android.view.View) ListView(android.widget.ListView) ListAdapter(android.widget.ListAdapter)

Example 67 with ListAdapter

use of android.widget.ListAdapter in project PullToRefresh-PinnedSection-ListView by tongcpp.

the class PullToRefreshListView method onRefreshing.

@Override
protected void onRefreshing(final boolean doScroll) {
    /**
		 * If we're not showing the Refreshing view, or the list is empty, the
		 * the header/footer views won't show so we use the normal method.
		 */
    ListAdapter adapter = mRefreshableView.getAdapter();
    if (!mListViewExtrasEnabled || !getShowViewWhileRefreshing() || null == adapter || adapter.isEmpty()) {
        super.onRefreshing(doScroll);
        return;
    }
    super.onRefreshing(false);
    final LoadingLayout origLoadingView, listViewLoadingView, oppositeListViewLoadingView;
    final int selection, scrollToY;
    switch(getCurrentMode()) {
        case MANUAL_REFRESH_ONLY:
        case PULL_FROM_END:
            origLoadingView = getFooterLayout();
            listViewLoadingView = mFooterLoadingView;
            oppositeListViewLoadingView = mHeaderLoadingView;
            selection = mRefreshableView.getCount() - 1;
            scrollToY = getScrollY() - getFooterSize();
            break;
        case PULL_FROM_START:
        default:
            origLoadingView = getHeaderLayout();
            listViewLoadingView = mHeaderLoadingView;
            oppositeListViewLoadingView = mFooterLoadingView;
            selection = 0;
            scrollToY = getScrollY() + getHeaderSize();
            break;
    }
    // Hide our original Loading View
    origLoadingView.reset();
    origLoadingView.hideAllViews();
    // Make sure the opposite end is hidden too
    oppositeListViewLoadingView.setVisibility(View.GONE);
    // Show the ListView Loading View and set it to refresh.
    listViewLoadingView.setVisibility(View.VISIBLE);
    listViewLoadingView.refreshing();
    if (doScroll) {
        // We need to disable the automatic visibility changes for now
        disableLoadingLayoutVisibilityChanges();
        // We scroll slightly so that the ListView's header/footer is at the
        // same Y position as our normal header/footer
        setHeaderScroll(scrollToY);
        // Make sure the ListView is scrolled to show the loading
        // header/footer
        mRefreshableView.setSelection(selection);
        // Smooth scroll as normal
        smoothScrollTo(0);
    }
}
Also used : ListAdapter(android.widget.ListAdapter) LoadingLayout(com.handmark.pulltorefresh.library.internal.LoadingLayout)

Example 68 with ListAdapter

use of android.widget.ListAdapter in project PullToRefresh-PinnedSection-ListView by tongcpp.

the class PinnedSectionListView method findCurrentSectionPosition.

int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();
    if (adapter instanceof SectionIndexer) {
        // try fast way by asking section indexer
        SectionIndexer indexer = (SectionIndexer) adapter;
        int sectionPosition = indexer.getSectionForPosition(fromPosition);
        int itemPosition = indexer.getPositionForSection(sectionPosition);
        int typeView = adapter.getItemViewType(itemPosition);
        if (isItemViewTypePinned(adapter, typeView)) {
            return itemPosition;
        }
    // else, no luck
    }
    // try slow way by looking through to the next section item above
    for (int position = fromPosition; position >= 0; position--) {
        int viewType = adapter.getItemViewType(position);
        if (isItemViewTypePinned(adapter, viewType))
            return position;
    }
    // no candidate found
    return -1;
}
Also used : SectionIndexer(android.widget.SectionIndexer) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter)

Example 69 with ListAdapter

use of android.widget.ListAdapter in project PullToRefresh-PinnedSection-ListView by tongcpp.

the class PinnedSectionListView method setAdapter.

@Override
public void setAdapter(ListAdapter adapter) {
    // assert adapter in debug mode
    if (BuildConfig.DEBUG && adapter != null) {
        if (!(adapter instanceof PinnedSectionListAdapter))
            throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?");
        if (adapter.getViewTypeCount() < 2)
            throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?");
    }
    // unregister observer at old adapter and register on new one
    ListAdapter oldAdapter = getAdapter();
    if (oldAdapter != null)
        oldAdapter.unregisterDataSetObserver(mDataSetObserver);
    if (adapter != null)
        adapter.registerDataSetObserver(mDataSetObserver);
    // destroy pinned shadow, if new adapter is not same as old one
    if (oldAdapter != adapter)
        destroyPinnedShadow();
    super.setAdapter(adapter);
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter)

Example 70 with ListAdapter

use of android.widget.ListAdapter in project PullToRefresh-PinnedSection-ListView by tongcpp.

the class PinnedSectionListView method findFirstVisibleSectionPosition.

int findFirstVisibleSectionPosition(int firstVisibleItem, int visibleItemCount) {
    ListAdapter adapter = getAdapter();
    for (int childIndex = 0; childIndex < visibleItemCount; childIndex++) {
        int position = firstVisibleItem + childIndex;
        int viewType = adapter.getItemViewType(position);
        if (isItemViewTypePinned(adapter, viewType))
            return position;
    }
    return -1;
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter)

Aggregations

ListAdapter (android.widget.ListAdapter)295 ListView (android.widget.ListView)104 View (android.view.View)94 AdapterView (android.widget.AdapterView)54 AbsListView (android.widget.AbsListView)47 WrapperListAdapter (android.widget.WrapperListAdapter)47 HeaderViewListAdapter (android.widget.HeaderViewListAdapter)43 TextView (android.widget.TextView)41 ViewGroup (android.view.ViewGroup)36 Paint (android.graphics.Paint)21 ArrayAdapter (android.widget.ArrayAdapter)21 Point (android.graphics.Point)18 SuppressLint (android.annotation.SuppressLint)16 SimpleCursorAdapter (android.widget.SimpleCursorAdapter)16 Cursor (android.database.Cursor)12 DialogInterface (android.content.DialogInterface)10 Bundle (android.os.Bundle)10 FrameLayout (android.widget.FrameLayout)10 ImageView (android.widget.ImageView)10 SectionIndexer (android.widget.SectionIndexer)10