本文整理了Java中android.widget.Adapter.getCount()
方法的一些代码示例,展示了Adapter.getCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Adapter.getCount()
方法的具体详情如下:
包路径:android.widget.Adapter
类名称:Adapter
方法名:getCount
暂无
代码示例来源:origin: stackoverflow.com
/**
* Computes the widest view in an adapter, best used when you need to wrap_content on a ListView, please be careful
* and don't use it on an adapter that is extremely numerous in items or it will take a long time.
*
* @param context Some context
* @param adapter The adapter to process
* @return The pixel width of the widest View
*/
public static int getWidestView(Context context, Adapter adapter) {
int maxWidth = 0;
View view = null;
FrameLayout fakeParent = new FrameLayout(context);
for (int i=0, count=adapter.getCount(); i<count; i++) {
view = adapter.getView(i, view, fakeParent);
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int width = view.getMeasuredWidth();
if (width > maxWidth) {
maxWidth = width;
}
}
return maxWidth;
}
代码示例来源:origin: square/assertj-android
public S hasCount(int count) {
isNotNull();
int actualCount = actual.getCount();
assertThat(actualCount) //
.overridingErrorMessage("Expected count <%s> but was <%s>.", count, actualCount) //
.isEqualTo(count);
return myself;
}
代码示例来源:origin: square/assertj-android
public S hasItem(Object expected, int index) {
isNotNull();
assertThat(actual.getCount())
.overridingErrorMessage("Index %s is out of bounds. The adapter holds %s items.",
index, actual.getCount())
.isGreaterThan(index);
final Object actualItem = actual.getItem(index);
assertThat(actualItem)
.overridingErrorMessage("Expected item at index %s to be <%s> but was <%s>.", index,
expected, actualItem)
.isEqualTo(expected);
return myself;
}
代码示例来源:origin: robolectric/robolectric
/**
* @return the items that are available to be clicked on
*/
public CharSequence[] getItems() {
Adapter adapter = getShadowAlertController().getAdapter();
int count = adapter.getCount();
CharSequence[] items = new CharSequence[count];
for (int i = 0; i < items.length; i++) {
items[i] = (CharSequence) adapter.getItem(i);
}
return items;
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void check(View view,
NoMatchingViewException noViewFoundException) {
Assert.assertTrue(view instanceof AdapterView);
Assert.assertEquals(count,
((AdapterView)view).getAdapter().getCount());
}
}
代码示例来源:origin: square/assertj-android
public S doesNotHaveItem(Object notExpected, int index) {
isNotNull();
assertThat(actual.getCount())
.overridingErrorMessage("Index %s is out of bounds. The adapter holds %s items.",
index, actual.getCount())
.isGreaterThan(index);
final Object actualItem = actual.getItem(index);
assertThat(actualItem)
.overridingErrorMessage("Expected item at index %s not to be <%s> but it was.", index,
notExpected, actualItem)
.isNotEqualTo(notExpected);
return myself;
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void check(View view,
NoMatchingViewException noViewFoundException) {
Assert.assertTrue(view instanceof AdapterView);
Assert.assertEquals(count,
((AdapterView)view).getAdapter().getCount());
}
}}
代码示例来源:origin: chentao0707/SimplifyReader
/**
* @return The data corresponding to the currently selected item, or
* null if there is nothing selected.
*/
public Object getSelectedItem() {
T adapter = getAdapter();
int selection = getSelectedItemPosition();
if (adapter != null && adapter.getCount() > 0 && selection >= 0) {
return adapter.getItem(selection);
} else {
return null;
}
}
代码示例来源:origin: chentao0707/SimplifyReader
/**
* Remember enough information to restore the screen state when the data has
* changed.
*
*/
void rememberSyncState() {
if (getChildCount() > 0) {
mNeedSync = true;
mSyncHeight = mLayoutHeight;
// Sync the based on the offset of the first view
View v = getChildAt(0);
T adapter = getAdapter();
if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) {
mSyncRowId = adapter.getItemId(mFirstPosition);
} else {
mSyncRowId = NO_ID;
}
mSyncPosition = mFirstPosition;
if (v != null) {
mSpecificTop = v.getTop();
}
mSyncMode = SYNC_FIRST_POSITION;
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testBuilderWithAdapter() throws Exception {
List<Integer> list = new ArrayList<>();
list.add(99);
list.add(88);
list.add(77);
ArrayAdapter<Integer> adapter = new ArrayAdapter<>(context, R.layout.main, R.id.title, list);
AlertDialog.Builder builder = new AlertDialog.Builder(application);
builder.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
assertTrue(alert.isShowing());
ShadowAlertDialog shadowAlertDialog = shadowOf(alert);
assertThat(shadowAlertDialog.getAdapter().getCount()).isEqualTo(3);
assertThat(shadowAlertDialog.getAdapter().getItem(0)).isEqualTo(99);
}
代码示例来源:origin: GeekGhost/Ghost
public void setSelection(int position) {
if (position < mAdapter.getCount()) {
this.nextAdapterCard = position;
removeAllViews();
requestLayout();
}
}
代码示例来源:origin: GeekGhost/Ghost
private void addNextCard() {
if (nextAdapterCard < mAdapter.getCount()) {
// TODO: Make view recycling work
// TODO: Instead of removing the view from here and adding it again when it's swiped
// ... don't remove and add to this instance: don't call removeView & addView in sequence.
View newBottomChild = mAdapter.getView(nextAdapterCard, null/*lastRemovedView*/, this);
if (hardwareAccelerationEnabled) {
//set backed by an off-screen buffer
newBottomChild.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
//set the initial Y value so card appears from under the deck
//newBottomChild.setY(paddingTop);
addAndMeasureChild(newBottomChild);
nextAdapterCard++;
}
setupTopCard();
}
代码示例来源:origin: GeekGhost/Ghost
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
// if we don't have an adapter, we don't need to do anything
if (mAdapter == null || mAdapter.getCount() == 0) {
nextAdapterCard = 0;
removeAllViewsInLayout();
return;
}
//pull in views from the adapter at the position the top of the deck is set to
//stop when you get to for cards or the end of the adapter
int childCount = getChildCount();
for (int i = childCount; i < NUMBER_OF_CARDS; ++i) {
addNextCard();
}
for (int i = 0; i < getChildCount(); ++i) {
positionItem(i);
}
//position the new children we just added and set up the top card with a listener etc
}
代码示例来源:origin: stackoverflow.com
final int dataPosition = i - getHeaderViewsCount();
final int childPosition = i - getFirstVisiblePosition();
if (dataPosition >= 0 && dataPosition < mAdapter.getCount()
&& getChildAt(childPosition) != null) {
Log.v(TAG, "Refreshing view (data=" + dataPosition + ",child=" + childPosition + ")");
代码示例来源:origin: xiepeijie/SwipeCardView
final int adapterCount = mAdapter.getCount();
if (adapterCount == 0) {
代码示例来源:origin: stackoverflow.com
static final int getAdapterPositionById(final Adapter adapter, final long id) throws NoSuchElementException {
final int count = adapter.getCount();
for (int pos = 0; pos < count; pos++) {
if (id == adapter.getItemId(pos)) {
return pos;
}
}
throw new NoSuchElementException();
}
代码示例来源:origin: stackoverflow.com
public List<User> retrieveAllItems(Spinner theSpinner) {
Adapter adapter = theSpinner.getAdapter();
int n = adapter.getCount();
List<User> users = new ArrayList<User>(n);
for (int i = 0; i < n; i++) {
User user = (User) adapter.getItem(i);
users.add(user);
}
return users;
}
代码示例来源:origin: com.actionbarsherlock/actionbarsherlock
private boolean isScrollableForAccessibility() {
T adapter = getAdapter();
if (adapter != null) {
final int itemCount = adapter.getCount();
return itemCount > 0
&& (getFirstVisiblePosition() > 0 || getLastVisiblePosition() < itemCount - 1);
}
return false;
}
代码示例来源:origin: org.robolectric/framework
/**
* @return the items that are available to be clicked on
*/
public CharSequence[] getItems() {
Adapter adapter = getShadowAlertController().getAdapter();
int count = adapter.getCount();
CharSequence[] items = new CharSequence[count];
for (int i = 0; i < items.length; i++) {
items[i] = (CharSequence) adapter.getItem(i);
}
return items;
}
代码示例来源:origin: binaryroot/CarouselView
@Override
public void setFocusable(boolean focusable) {
final T adapter = getAdapter();
final boolean empty = adapter == null || adapter.getCount() == 0;
mDesiredFocusableState = focusable;
if (!focusable) {
mDesiredFocusableInTouchModeState = false;
}
super.setFocusable(focusable && (!empty || isInFilterMode()));
}
内容来源于网络,如有侵权,请联系作者删除!