android.widget.ListView.getCount()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中android.widget.ListView.getCount()方法的一些代码示例,展示了ListView.getCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListView.getCount()方法的具体详情如下:
包路径:android.widget.ListView
类名称:ListView
方法名:getCount

ListView.getCount介绍

暂无

代码示例

代码示例来源:origin: k9mail/k-9

public void onMoveDown() {
  int currentPosition = listView.getSelectedItemPosition();
  if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
    currentPosition = listView.getFirstVisiblePosition();
  }
  if (currentPosition < listView.getCount()) {
    listView.setSelection(currentPosition + 1);
  }
}

代码示例来源:origin: k9mail/k-9

@Override
  public void onClick(DialogInterface dialog, int which) {
    ListView listView = ((AlertDialog) dialog).getListView();
    SparseBooleanArray pos = listView.getCheckedItemPositions();
    boolean includeGlobals = mImportContents.globalSettings && pos.get(0);
    List<String> accountUuids = new ArrayList<>();
    int start = mImportContents.globalSettings ? 1 : 0;
    for (int i = start, end = listView.getCount(); i < end; i++) {
      if (pos.get(i)) {
        accountUuids.add(mImportContents.accounts.get(i - start).uuid);
      }
    }
    /*
     * TODO: Think some more about this. Overwriting could change the store
     * type. This requires some additional code in order to work smoothly
     * while the app is running.
     */
    boolean overwrite = false;
    dialog.dismiss();
    activity.setNonConfigurationInstance(null);
    ImportAsyncTask importAsyncTask = new ImportAsyncTask(activity,
        includeGlobals, accountUuids, overwrite, mUri);
    activity.setNonConfigurationInstance(importAsyncTask);
    importAsyncTask.execute();
  }
});

代码示例来源:origin: stackoverflow.com

ListView listView;
Runnable fitsOnScreen = new Runnable() {
  @Override
  public void run() {
    int last = listView.getLastVisiblePosition();
    if(last == listView.getCount() - 1 && listView.getChildAt(last).getBottom() <= listView.getHeight()) {
      // It fits!
    }
    else {
      // It doesn't fit...
    }
  }
};

代码示例来源:origin: stackoverflow.com

int count = mList.getCount();
mScrollCompleted = false;
final Object[] sections = mSections;

代码示例来源:origin: k9mail/k-9

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  // Shortcuts that work no matter what is selected
  if (K9.useVolumeKeysForListNavigationEnabled() &&
      (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
          keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
    final ListView listView = getListView();
    int currentPosition = listView.getSelectedItemPosition();
    if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
      currentPosition = listView.getFirstVisiblePosition();
    }
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && currentPosition > 0) {
      listView.setSelection(currentPosition - 1);
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN &&
        currentPosition < listView.getCount()) {
      listView.setSelection(currentPosition + 1);
    }
    return true;
  }
  return super.onKeyDown(keyCode, event);
}

代码示例来源:origin: stackoverflow.com

public static int getCheckedItemCount(ListView listView)
{
  if (Build.VERSION.SDK_INT >= 11) return listView.getCheckedItemCount();
  else
  {
    int count = 0;
    for (int i = listView.getCount() - 1; i >= 0; i--)
      if (listView.isItemChecked(i)) count++;
    return count;
  }
}

代码示例来源:origin: stackoverflow.com

public static void ensureVisible(ListView listView, int pos)
{
  if (listView == null)
  {
    return;
  }

  if(pos < 0 || pos >= listView.getCount())
  {
    return;
  }

  int first = listView.getFirstVisiblePosition();
  int last = listView.getLastVisiblePosition();

  if (pos < first)
  {
    listView.setSelection(pos);
    return;
  }

  if (pos >= last)
  {
    listView.setSelection(1 + pos - (last - first));
    return;
  }
}

代码示例来源:origin: huangfangyi/FanXin

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
  if(scrollState == OnScrollListener.SCROLL_STATE_IDLE){
    if(listView.getCount() != 0){
      int lasPos = view.getLastVisiblePosition();
      if(hasMoreData && !isLoading && lasPos == listView.getCount()-1){
        loadAndShowData();
      }
    }
  }
}

代码示例来源:origin: tianshaojie/AndroidFine

originalLoadingLayout = getFooterLayout();
listViewLoadingLayout = mFooterLoadingView;
selection = mRefreshableView.getCount() - 1;
scrollToHeight = getFooterSize();
scrollLvToEdge = Math.abs(mRefreshableView.getLastVisiblePosition() - selection) <= 1;

代码示例来源:origin: stackoverflow.com

private int calculateHeight(ListView list) {

  int height = 0;

  for (int i = 0; i < list.getCount(); i++) {
    View childView = list.getAdapter().getView(i, null, list);
    childView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    height+= childView.getMeasuredHeight();
  }

  //dividers height
  height += list.getDividerHeight() * list.getCount();

  return height;
}

代码示例来源:origin: huangfangyi/YiChat

@Override
public void refreshListView() {
  adapter.notifyDataSetChanged();
  if (listView.getCount() > 0) {
    listView.setSelection(listView.getCount() - 1);
  }
}

代码示例来源:origin: huangfangyi/FanXin

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
  if(scrollState == OnScrollListener.SCROLL_STATE_IDLE){
    if(cursor != null){
      int lasPos = view.getLastVisiblePosition();
      if(hasMoreData && !isLoading && lasPos == listView.getCount()-1){
        loadAndShowData();
      }
    }
  }
}

代码示例来源:origin: huangfangyi/YiChat

@Override
  public void run() {
    listView.smoothScrollToPosition(listView.getCount() - 1);
  }
}, 500);

代码示例来源:origin: stackoverflow.com

.setNeutralButton(R.string.set_all, 
         new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
         ListView list = ((AlertDialog) dialog).getListView();
         for (int i=0; i < list.getCount(); i++) {
           list.setItemChecked(i, true);
         }
       }
  })

代码示例来源:origin: stackoverflow.com

private int sumMyIntValues(ListView myList) {
  int sum=0;
  for (int i = 0; i < myList.getCount(); i++) {
    View v = myList.getChildAt(i);
    TextView myView = (TextView) v.findViewById(R.id.myView);
    sum = sum + Integer.parseInt( myView.getText().toString() )
  }
  return sum;
}

代码示例来源:origin: tianshaojie/AndroidFine

listViewLoadingView = mFooterLoadingView;
oppositeListViewLoadingView = mHeaderLoadingView;
selection = mRefreshableView.getCount() - 1;
scrollToY = getScrollY() - getFooterSize();
break;

代码示例来源:origin: vanilla-music/vanilla

/**
 * Restores the saved scrolling position
 */
private void restorePosition(int index) {
  // Restore scrolling position if present and valid
  Integer curPos = sLruAdapterPos.popPosition(mAdapters[index]);
  if (curPos != null && curPos < mLists[index].getCount())
    mLists[index].setSelection(curPos);
}

代码示例来源:origin: sealtalk/sealtalk-android

@Override
  public void run() {
    listView.requestFocusFromTouch();
    listView.setSelection(listView.getCount() - listView.getFooterViewsCount() - listView.getHeaderViewsCount());
  }
}, 100);

代码示例来源:origin: nglauber/dominando_android2

@Override
public void onDestroyActionMode(ActionMode actionMode) {
  mActionMode = null;
  for (int i = 0; i < mListView.getCount(); i++) {
    mListView.setItemChecked(i, false);
  }
  mListView.clearChoices();
  mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
  limparBusca();
}

代码示例来源:origin: blurpy/kouchat-android

private Bitmap getBitmapForUser(final int numberOfUsers, final int userNumber) {
  solo.sleep(1000);
  assertEquals(numberOfUsers, solo.getCurrentViews(ListView.class).get(0).getCount());
  final LinearLayout row = (LinearLayout) solo.getCurrentViews(ListView.class).get(0).getChildAt(userNumber - 1);
  final ImageView imageAtRow = (ImageView) row.getChildAt(0);
  final BitmapDrawable drawable = (BitmapDrawable) imageAtRow.getDrawable();
  return drawable.getBitmap();
}

相关文章

ListView类方法