Example usage for android.util SparseIntArray append

List of usage examples for android.util SparseIntArray append

Introduction

In this page you can find the example usage for android.util SparseIntArray append.

Prototype

public void append(int key, int value) 

Source Link

Document

Puts a key/value pair into the array, optimizing for the case where the key is greater than all existing keys in the array.

Usage

From source file:com.tct.fw.ex.photo.adapters.BaseCursorPagerAdapter.java

/**
 * Sets the {@link #mItemPosition} instance variable with the current mapping of
 * row id to cursor position./*from   w  w w.  j ava 2s  . co m*/
 */
private void setItemPosition() {
    if (mCursor == null || mCursor.isClosed()) {
        mItemPosition = null;
        return;
    }

    SparseIntArray itemPosition = new SparseIntArray(mCursor.getCount());

    mCursor.moveToPosition(-1);
    while (mCursor.moveToNext()) {
        final int rowId = mCursor.getString(mRowIDColumn).hashCode();
        final int position = mCursor.getPosition();

        itemPosition.append(rowId, position);
    }
    mItemPosition = itemPosition;
}

From source file:com.google.android.flexbox.FlexboxHelper.java

private int[] sortOrdersIntoReorderedIndices(int childCount, List<Order> orders, SparseIntArray orderCache) {
    Collections.sort(orders);/*  w  w  w.  j  av  a2s  .  c  om*/
    orderCache.clear();
    int[] reorderedIndices = new int[childCount];
    int i = 0;
    for (Order order : orders) {
        reorderedIndices[i] = order.index;
        orderCache.append(order.index, order.order);
        i++;
    }
    return reorderedIndices;
}