Example usage for android.widget ListAdapter getCount

List of usage examples for android.widget ListAdapter getCount

Introduction

In this page you can find the example usage for android.widget ListAdapter getCount.

Prototype

int getCount();

Source Link

Document

How many items are in the data set represented by this Adapter.

Usage

From source file:com.dm.xz.views.PinnedSectionListView.java

int findFirstVisibleSectionPosition(int firstVisibleItem, int visibleItemCount) {
    ListAdapter adapter = getAdapter();

    int adapterDataCount = adapter.getCount();
    if (getLastVisiblePosition() >= adapterDataCount)
        return -1; // dataset has changed, no candidate

    if (firstVisibleItem + visibleItemCount >= adapterDataCount) {//added to prevent index Outofbound (in case)
        visibleItemCount = adapterDataCount - firstVisibleItem;
    }//w ww . j av  a 2s.c o m

    for (int childIndex = 0; childIndex < visibleItemCount; childIndex++) {
        int position = firstVisibleItem + childIndex;
        int viewType = adapter.getItemViewType(position);
        if (isItemViewTypePinned(adapter, viewType))
            return position;
    }
    return -1;
}

From source file:com.dm.xz.views.PinnedSectionListView.java

int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();

    if (fromPosition >= adapter.getCount())
        return -1; // dataset has changed, no candidate

    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
    }//from  www  .j ava 2 s. c  o  m

    // 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;
    }
    return -1; // no candidate found
}

From source file:org.kontalk.ui.ConversationsActivity.java

@Override
public boolean onSearchRequested() {
    ConversationListFragment fragment = getListFragment();

    ListAdapter list = fragment.getListAdapter();
    // no data found
    if (list == null || list.getCount() == 0)
        return false;

    toggleSearch();/*www.ja v  a  2s .  c o  m*/
    return false;
}

From source file:org.solovyev.android.widget.menu.CustomPopupMenuHelper.java

private int measureContentWidth() {
    // Menus don't tend to be long, so this is more sane than it looks.
    int maxWidth = 0;
    View itemView = null;/*from  w  w w  .jav  a 2 s.  co m*/
    int itemType = 0;

    final ListAdapter adapter = mAdapter;
    final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }

        if (mMeasureParent == null) {
            mMeasureParent = new FrameLayout(mContext);
        }

        itemView = adapter.getView(i, itemView, mMeasureParent);
        itemView.measure(widthMeasureSpec, heightMeasureSpec);

        final int itemWidth = itemView.getMeasuredWidth();
        if (itemWidth >= mPopupMaxWidth) {
            return mPopupMaxWidth;
        } else if (itemWidth > maxWidth) {
            maxWidth = itemWidth;
        }
    }

    return maxWidth;
}

From source file:net.naonedbus.fragment.CustomListFragment.java

/**
 * Gestion du changement du contenu de l'adapter : affichage ou non du
 * message comme quoi la liste est vide.
 * /*ww  w .j  a  va2s  . com*/
 * @param adapter
 */
public void onListAdapterChange(final ListAdapter adapter) {
    if (DBG)
        Log.d(LOG_TAG + "$" + getClass().getSimpleName(), "onListAdapterChange");

    if (adapter == null || adapter.getCount() == 0) {
        showMessage(mMessageEmptyTitleId, mMessageEmptySummaryId, mMessageEmptyDrawableId);
    } else {
        showContent();
    }
}

From source file:com.actionbarsherlock.internal.view.menu.MenuPopupHelper.java

private int measureContentWidth(ListAdapter adapter) {
    // Menus don't tend to be long, so this is more sane than it looks.
    int width = 0;
    View itemView = null;//from  w ww . ja v  a  2 s  . c  o  m
    int itemType = 0;
    final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        if (mMeasureParent == null) {
            mMeasureParent = new FrameLayout(mContext);
        }
        itemView = adapter.getView(i, itemView, mMeasureParent);
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }
    return width;
}

From source file:org.lol.reddit.fragments.CommentListingFragment.java

public void handleCommentVisibilityToggle(RedditCommentView view) {

    final boolean isCollapsed = view.handleVisibilityToggle();
    outerAdapter.notifyDataSetChanged();

    if (isCollapsed) {

        final RedditPreparedComment comment = view.getComment();
        final ListAdapter adapter = lv.getAdapter();
        final int count = adapter.getCount();

        for (int i = 0; i < count; i++) {
            if (adapter.getItem(i) == comment) {

                if (i == lv.getFirstVisiblePosition()) {
                    lv.smoothScrollToPosition(i);
                }/*w  w w .ja va  2s.  c  o  m*/

                break;
            }
        }
    }
}

From source file:com.library.core.view.HorizontalListView.java

/**
 * Find a position that can be selected (i.e., is not a separator).
 * //from   w ww.ja v a 2  s  .  c  o m
 * @param position
 *            The starting position to look at.
 * @param lookDown
 *            Whether to look down for other positions.
 * @return The next selectable position starting at position and then
 *         searching either up or down. Returns {@link #INVALID_POSITION} if
 *         nothing can be found.
 */
int lookForSelectablePosition(int position, boolean lookDown) {
    final ListAdapter adapter = mAdapter;
    if (adapter == null || isInTouchMode()) {
        return INVALID_POSITION;
    }

    final int count = adapter.getCount();
    if (!adapter.areAllItemsEnabled()) {
        if (lookDown) {
            position = Math.max(0, position);
            while (position < count && !adapter.isEnabled(position)) {
                position++;
            }
        } else {
            position = Math.min(position, count - 1);
            while (position >= 0 && !adapter.isEnabled(position)) {
                position--;
            }
        }

        if (position < 0 || position >= count) {
            return INVALID_POSITION;
        }
        return position;
    } else {
        if (position < 0 || position >= count) {
            return INVALID_POSITION;
        }
        return position;
    }
}

From source file:com.ubuntuone.android.files.activity.PreferencesActivity.java

private void openPreference(String key) {
    PreferenceScreen screen = getPreferenceScreen();
    Log.d(TAG, "screen not null");
    if (screen != null) {
        ListAdapter adapter = getPreferenceScreen().getRootAdapter();
        for (int i = 0; i < adapter.getCount(); i++) {
            Preference p = (Preference) adapter.getItem(i);
            Log.d(TAG, "key is: " + p.getKey());
            if (p.getKey().equals(key)) {
                screen.onItemClick(null, null, i, 0);
                break;
            }//from   w w w . j  a  v a  2s .c om
        }
    }
}

From source file:de.vanita5.twittnuker.fragment.support.BaseSupportListFragment.java

@Override
public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount,
        final int totalItemCount) {
    final ListAdapter adapter = getListAdapter();
    if (adapter == null)
        return;/*from w ww . j a  va  2 s. c  om*/
    final boolean reachedTop = firstVisibleItem == 0;
    final boolean reachedBottom = firstVisibleItem + visibleItemCount >= totalItemCount
            && totalItemCount >= visibleItemCount;

    if (mReachedBottom != reachedBottom) {
        mReachedBottom = reachedBottom;
        if (mReachedBottom && mNotReachedBottomBefore) {
            mNotReachedBottomBefore = false;
            return;
        }
        if (mReachedBottom && adapter.getCount() > visibleItemCount) {
            onReachedBottom();
        }
    }
    if (mReachedTop != reachedTop) {
        mReachedTop = reachedTop;
        if (mReachedTop && mNotReachedTopBefore) {
            mNotReachedTopBefore = false;
            return;
        }
        if (mReachedTop && adapter.getCount() > visibleItemCount) {
            onReachedTop();
        }
    }
}