android.widget.ListAdapter#getItemId ( )源码实例Demo

下面列出了android.widget.ListAdapter#getItemId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PullToRefreshLibrary   文件: ExtendableListView.java
/**
 * Remember enough information to restore the screen state when the data has
 * changed.
 */
void rememberSyncState() {
	if (getChildCount() > 0) {
		mNeedSync = true;
		mSyncHeight = getHeight();
		// Sync the based on the offset of the first view
		View v = getChildAt(0);
		ListAdapter adapter = getAdapter();
		if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) {
			mSyncRowId = adapter.getItemId(mFirstPosition);
		} else {
			mSyncRowId = NO_ID;
		}
		if (v != null) {
			mSpecificTop = v.getTop();
		}
		mSyncPosition = mFirstPosition;
	}
}
 
源代码2 项目: ListViewAnimations   文件: DragAndDropHandler.java
/**
 * Retrieves the {@code View} in the list corresponding to itemId.
 *
 * @return the {@code View}, or {@code null} if not found.
 */
@Nullable
private View getViewForId(final long itemId) {
    ListAdapter adapter = mAdapter;
    if (itemId == INVALID_ID || adapter == null) {
        return null;
    }

    int firstVisiblePosition = mWrapper.getFirstVisiblePosition();

    View result = null;
    for (int i = 0; i < mWrapper.getChildCount() && result == null; i++) {
        int position = firstVisiblePosition + i;
        if (position - mWrapper.getHeaderViewsCount() >= 0) {
            long id = adapter.getItemId(position - mWrapper.getHeaderViewsCount());
            if (id == itemId) {
                result = mWrapper.getChildAt(i);
            }
        }
    }
    return result;
}
 
源代码3 项目: ALLGO   文件: DynamicListView.java
/** Retrieves the view in the list corresponding to itemID */
public View getViewForID(long itemID) {
	int firstVisiblePosition = getFirstVisiblePosition();
	ListAdapter adapter = getAdapter();
	if (!adapter.hasStableIds()) {
		throw new IllegalStateException("Adapter doesn't have stable ids! Make sure your adapter has stable ids, and override hasStableIds() to return true.");
	}

	for (int i = 0; i < getChildCount(); i++) {
		View v = getChildAt(i);
		int position = firstVisiblePosition + i;
		long id = adapter.getItemId(position);
		if (id == itemID) {
			return v;
		}
	}
	return null;
}
 
源代码4 项目: UltimateAndroid   文件: ExtendableListView.java
/**
 * Remember enough information to restore the screen state when the data has
 * changed.
 */
void rememberSyncState() {
    if (getChildCount() > 0) {
        mNeedSync = true;
        mSyncHeight = getHeight();
        // Sync the based on the offset of the first view
        View v = getChildAt(0);
        ListAdapter adapter = getAdapter();
        if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) {
            mSyncRowId = adapter.getItemId(mFirstPosition);
        }
        else {
            mSyncRowId = NO_ID;
        }
        if (v != null) {
            mSpecificTop = v.getTop();
        }
        mSyncPosition = mFirstPosition;
    }
}
 
源代码5 项目: UltimateAndroid   文件: DynamicListView.java
/**
 * Retrieves the view in the list corresponding to itemId
 */
private View getViewForId(long itemId) {
    int firstVisiblePosition = getFirstVisiblePosition();
    ListAdapter adapter = getAdapter();
    if (!adapter.hasStableIds()) {
        throw new IllegalStateException("Adapter doesn't have stable ids! Make sure your adapter has stable ids, and override hasStableIds() to return true.");
    }

    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        int position = firstVisiblePosition + i;
        long id = adapter.getItemId(position);
        if (id == itemId) {
            return v;
        }
    }
    return null;
}
 
/**
 * Retrieves the view in the list corresponding to itemId
 */
private View getViewForId(long itemId) {
    int firstVisiblePosition = getFirstVisiblePosition();
    ListAdapter adapter = getAdapter();
    if (!adapter.hasStableIds()) {
        throw new IllegalStateException("Adapter doesn't have stable ids! Make sure your adapter has stable ids, and override hasStableIds() to return true.");
    }

    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        int position = firstVisiblePosition + i;
        long id = adapter.getItemId(position);
        if (id == itemId) {
            return v;
        }
    }
    return null;
}
 
源代码7 项目: letv   文件: HListView.java
@Deprecated
public long[] getCheckItemIds() {
    if (this.mAdapter != null && this.mAdapter.hasStableIds()) {
        return getCheckedItemIds();
    }
    if (this.mChoiceMode == 0 || this.mCheckStates == null || this.mAdapter == null) {
        return new long[0];
    }
    SparseArrayCompat<Boolean> states = this.mCheckStates;
    int count = states.size();
    long[] ids = new long[count];
    ListAdapter adapter = this.mAdapter;
    int i = 0;
    int checkedCount = 0;
    while (i < count) {
        int checkedCount2;
        if (((Boolean) states.valueAt(i)).booleanValue()) {
            checkedCount2 = checkedCount + 1;
            ids[checkedCount] = adapter.getItemId(states.keyAt(i));
        } else {
            checkedCount2 = checkedCount;
        }
        i++;
        checkedCount = checkedCount2;
    }
    if (checkedCount == count) {
        return ids;
    }
    long[] result = new long[checkedCount];
    System.arraycopy(ids, 0, result, 0, checkedCount);
    return result;
}
 
源代码8 项目: Onosendai   文件: ScrollState.java
private void applyToListView (final ListView lv) {
	// NOTE if this seems unreliable try wrapping setSelection*() calls in lv.post(...).
	final ListAdapter adapter = lv.getAdapter();

	if (this.itemId >= 0L) {
		for (int i = 0; i < adapter.getCount(); i++) {
			if (adapter.getItemId(i) == this.itemId) {
				lv.setSelectionFromTop(i, this.top);
				return;
			}
		}
	}

	// Also search by time before giving up.
	if (this.itemTime > 0L && adapter instanceof TweetListCursorAdapter) {
		final TweetListCursorAdapter tlca = (TweetListCursorAdapter) adapter;
		for (int i = 0; i < tlca.getCount(); i++) {
			final long itime = tlca.getItemTime(i);
			if (itime > 0L && itime <= this.itemTime) {
				lv.setSelectionFromTop(i, 0);
				return;
			}
		}
		LOG.w("Failed to restore scroll state %s to list of %s items.", this, tlca.getCount());
	}
	else {
		LOG.w("Failed to restore scroll state %s.", this);
	}

	lv.setSelection(lv.getCount() - 1);
}
 
源代码9 项目: BLE   文件: MergeAdapter.java
public long getItemId(int position) {
    int size;
    for (Iterator i$ = this.getPieces().iterator(); i$.hasNext(); position -= size) {
        ListAdapter piece = (ListAdapter) i$.next();
        size = piece.getCount();
        if (position < size) {
            return piece.getItemId(position);
        }
    }

    return -1L;
}
 
源代码10 项目: AndroidBleManager   文件: MergeAdapter.java
/**
 * Get the row id associated with the specified position
 * in the list.
 *
 * @param position
 *          Position of the item whose data we want
 */
@Override
public long getItemId(int position) {
    for (ListAdapter piece : getPieces()) {
        int size=piece.getCount();

        if (position < size) {
            return(piece.getItemId(position));
        }

        position-=size;
    }

    return(-1);
}
 
源代码11 项目: Kore   文件: DynamicListView.java
/**
 * Stores a reference to the views above and below the item currently
 * corresponding to the hover cell. It is important to note that if this
 * item is either at the top or bottom of the list, mAboveItemId or mBelowItemId
 * may be invalid.
 */
private void updateNeighborViewsForID(long itemID) {
    int position = getPositionForID(itemID);
    ListAdapter adapter = getAdapter();
    mAboveItemId = adapter.getItemId(position - 1);
    mBelowItemId = adapter.getItemId(position + 1);
}
 
源代码12 项目: Kore   文件: DynamicListView.java
/** Retrieves the view in the list corresponding to itemID */
public View getViewForID (long itemID) {
    int firstVisiblePosition = getFirstVisiblePosition();
    ListAdapter adapter = getAdapter();
    for(int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        int position = firstVisiblePosition + i;
        long id = adapter.getItemId(position);
        if (id == itemID) {
            return v;
        }
    }
    return null;
}
 
源代码13 项目: Ninja   文件: DynamicGridView.java
public View getViewForId(long itemId) {
    int firstVisiblePosition = getFirstVisiblePosition();
    ListAdapter adapter = getAdapter();
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        int position = firstVisiblePosition + i;
        long id = adapter.getItemId(position);
        if (id == itemId) {
            return v;
        }
    }
    return null;
}
 
源代码14 项目: android_maplibui   文件: ReorderedLayerView.java
/**
 * Stores a reference to the views above and below the item currently corresponding to the hover
 * cell. It is important to note that if this item is either at the top or bottom of the list,
 * mAboveItemId or mBelowItemId may be invalid.
 */
protected void updateNeighborViewsForID(long itemID)
{
    int position = getPositionForID(itemID);
    ListAdapter adapter = getAdapter();
    mAboveItemId = adapter.getItemId(position - 1);
    mBelowItemId = adapter.getItemId(position + 1);
}
 
源代码15 项目: android_maplibui   文件: ReorderedLayerView.java
/**
 * Retrieves the view in the list corresponding to itemID
 */
public View getViewForID(long itemID)
{
    int firstVisiblePosition = getFirstVisiblePosition();
    ListAdapter adapter = getAdapter();
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        int position = firstVisiblePosition + i;
        long id = adapter.getItemId(position);
        if (id == itemID) {
            return v;
        }
    }
    return null;
}
 
源代码16 项目: Klyph   文件: HListView.java
/**
 * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE}.
 * 
 * @return A new array which contains the id of each checked item in the list.
 * 
 * @deprecated Use {@link #getCheckedItemIds()} instead.
 */
@Deprecated
public long[] getCheckItemIds() {
	// Use new behavior that correctly handles stable ID mapping.
	if ( mAdapter != null && mAdapter.hasStableIds() ) {
		return getCheckedItemIds();
	}

	// Old behavior was buggy, but would sort of work for adapters without stable IDs.
	// Fall back to it to support legacy apps.
	if ( mChoiceMode != ListView.CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null ) {
		final SparseBooleanArray states = mCheckStates;
		final int count = states.size();
		final long[] ids = new long[count];
		final ListAdapter adapter = mAdapter;

		int checkedCount = 0;
		for ( int i = 0; i < count; i++ ) {
			if ( states.valueAt( i ) ) {
				ids[checkedCount++] = adapter.getItemId( states.keyAt( i ) );
			}
		}

		// Trim array if needed. mCheckStates may contain false values
		// resulting in checkedCount being smaller than count.
		if ( checkedCount == count ) {
			return ids;
		} else {
			final long[] result = new long[checkedCount];
			System.arraycopy( ids, 0, result, 0, checkedCount );

			return result;
		}
	}
	return new long[0];
}
 
源代码17 项目: DynamicGrid   文件: DynamicGridView.java
public View getViewForId(long itemId) {
    int firstVisiblePosition = getFirstVisiblePosition();
    ListAdapter adapter = getAdapter();
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        int position = firstVisiblePosition + i;
        long id = adapter.getItemId(position);
        if (id == itemId) {
            return v;
        }
    }
    return null;
}
 
源代码18 项目: SimpleExplorer   文件: MergeAdapter.java
/**
 * Get the row id associated with the specified position in the list.
 *
 * @param position Position of the item whose data we want
 */
public long getItemId(int position) {
    for (ListAdapter piece : pieces) {
        int size = piece.getCount();

        if (position < size) {
            return piece.getItemId(position);
        }

        position -= size;
    }

    return -1;
}
 
源代码19 项目: mimicry   文件: MergeAdapter.java
/**
 * Get the row id associated with the specified position in the list.
 * @param position Position of the item whose data we want
 */
public long getItemId(int position) {
	for (ListAdapter piece : pieces) {
		int size = piece.getCount();

		if (position < size) {
			return (piece.getItemId(position));
		}

		position -= size;
	}

	return (-1);
}
 
/**
 * Stores a reference to the views above and below the item currently
 * corresponding to the hover cell. It is important to note that if this
 * item is either at the top or bottom of the list, mAboveItemId or mBelowItemId
 * may be invalid.
 */
private void updateNeighborViewsForId(long itemId) {
    int position = getPositionForId(itemId);
    ListAdapter adapter = getAdapter();
    if (!adapter.hasStableIds()) {
        throw new IllegalStateException("Adapter doesn't have stable ids! Make sure your adapter has stable ids, and override hasStableIds() to return true.");
    }

    mAboveItemId = position - 1 >= 0 ? adapter.getItemId(position - 1) : INVALID_ROW_ID;
    mBelowItemId = position + 1 < adapter.getCount() ? adapter.getItemId(position + 1) : INVALID_ROW_ID;
}