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

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

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

ListView.getFirstVisiblePosition介绍

暂无

代码示例

代码示例来源:origin: Naoki2015/CircleDemo

@Override
  public int getFirstVisiblePosition() {
    return mListView.getFirstVisiblePosition();
  }
}

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

public View getViewByPosition(int pos, ListView listView) {
  final int firstListItemPosition = listView.getFirstVisiblePosition();
  final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

  if (pos < firstListItemPosition || pos > lastListItemPosition ) {
    return listView.getAdapter().getView(pos, null, listView);
  } else {
    final int childIndex = pos - firstListItemPosition;
    return listView.getChildAt(childIndex);
  }
}

代码示例来源:origin: joyoyao/superCleanMaster

public static int getScrollY(ListView lv) {
  View c = lv.getChildAt(0);
  if (c == null) {
    return 0;
  }
  int firstVisiblePosition = lv.getFirstVisiblePosition();
  int top = c.getTop();
  int scrollY = -top + firstVisiblePosition * c.getHeight();
  return scrollY;
}

代码示例来源:origin: alexvasilkov/GestureViews

@Override
boolean isShownInList(ListView list, int pos) {
  return pos >= list.getFirstVisiblePosition() && pos <= list.getLastVisiblePosition();
}

代码示例来源:origin: joyoyao/superCleanMaster

private int calculateScrollYList() {
  View c = mListView.getChildAt(0);
  if (c == null) {
    return 0;
  }
  //TODO support more than 1 header?
  int firstVisiblePosition = mListView.getFirstVisiblePosition();
  int top = c.getTop();
  int headerHeight = 0;
  if (firstVisiblePosition >= 1) { //TODO >= number of header
    headerHeight = mHeightHeader;
  }
  return -top + firstVisiblePosition * c.getHeight() + headerHeight;
}

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

private int mLastFirstVisibleItem;
private boolean mIsScrollingUp;

public void onScrollStateChanged(AbsListView view, int scrollState) {
  final ListView lw = getListView();

  if (view.getId() == lw.getId()) {
    final int currentFirstVisibleItem = lw.getFirstVisiblePosition();

    if (currentFirstVisibleItem > mLastFirstVisibleItem) {
      mIsScrollingUp = false;
    } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
      mIsScrollingUp = true;
    }

    mLastFirstVisibleItem = currentFirstVisibleItem;
  } 
}

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

setOnScrollListener(new OnScrollListener(){
 public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
  // TODO Auto-generated method stub
 }
 public void onScrollStateChanged(AbsListView view, int scrollState) {
  // TODO Auto-generated method stub
  final ListView lw = getListView();
   if(scrollState == 0) 
  Log.i("a", "scrolling stopped...");
   if (view.getId() == lw.getId()) {
   final int currentFirstVisibleItem = lw.getFirstVisiblePosition();
    if (currentFirstVisibleItem > mLastFirstVisibleItem) {
     mIsScrollingUp = false;
     Log.i("a", "scrolling down...");
   } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
     mIsScrollingUp = true;
     Log.i("a", "scrolling up...");
   }
   mLastFirstVisibleItem = currentFirstVisibleItem;
 } 
 }
});

代码示例来源:origin: daimajia/AndroidSwipeLayout

@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
  }
});

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

public View getViewByPosition(int position, ListView listView) {
  final int firstListItemPosition = listView.getFirstVisiblePosition();
  final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

  if (position < firstListItemPosition || position > lastListItemPosition ) {
    return listView.getAdapter().getView(position, null, listView);
  } else {
    final int childIndex = position - firstListItemPosition;
    return listView.getChildAt(childIndex);
  }
}

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

ListView list = getListView();
int start = list.getFirstVisiblePosition();
for(int i=start, j=list.getLastVisiblePosition();i<=j;i++)
  if(target==list.getItemAtPosition(i)){
    View view = list.getChildAt(i-start);
    list.getAdapter().getView(i, view, list);
    break;
  }

代码示例来源:origin: facebook/facebook-android-sdk

private void reprioritizeDownloads() {
  int lastVisibleItem = listView.getLastVisiblePosition();
  if (lastVisibleItem >= 0) {
    int firstVisibleItem = listView.getFirstVisiblePosition();
    adapter.prioritizeViewRange(firstVisibleItem, lastVisibleItem, PROFILE_PICTURE_PREFETCH_BUFFER);
  }
}

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

ListView list = getListView();
int start = list.getFirstVisiblePosition();
for(int i=start, j=list.getLastVisiblePosition();i<=j;i++)
  if(target==list.getItemAtPosition(i)){
    View view = list.getChildAt(i-start);
    list.getAdapter().getView(i, view, list);
    break;
  }

代码示例来源:origin: alexvasilkov/GestureViews

@Override
  public View getViewAt(int position) {
    View itemView = list.getChildAt(position - list.getFirstVisiblePosition());
    return itemView == null ? null : ListAdapter.getImageView(itemView);
  }
};

代码示例来源:origin: cSploit/android

@Override
  public void run() {
    if (lv == null)
      return;
    synchronized (this) {
      int start = lv.getFirstVisiblePosition();
      int end = Math.min(lv.getLastVisiblePosition(), list.size());
      for (int i = start; i <= end; i++)
        if (target == list.get(i)) {
          View view = lv.getChildAt(i - start);
          getView(i, view, lv);
          break;
        }
    }
  }
});

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

public void onMoveUp() {
  int currentPosition = listView.getSelectedItemPosition();
  if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
    currentPosition = listView.getFirstVisiblePosition();
  }
  if (currentPosition > 0) {
    listView.setSelection(currentPosition - 1);
  }
}

代码示例来源: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: umano/AndroidSlidingUpPanel

View firstChild = lv.getChildAt(0);
  return lv.getFirstVisiblePosition() * firstChild.getHeight() - firstChild.getTop();
} else {
  View lastChild = lv.getChildAt(lv.getChildCount() - 1);

代码示例来源:origin: ankidroid/Anki-Android

/**
   * Turn off Multi-Select Mode and return to normal state
   */
  private void endMultiSelectMode() {
    mCheckedCardPositions.clear();
    mInMultiSelectMode = false;
    // If view which was originally selected when entering multi-select is visible then maintain its position
    View view = mCardsListView.getChildAt(mLastSelectedPosition - mCardsListView.getFirstVisiblePosition());
    if (view != null) {
      recenterListView(view);
    }
    // update adapter to remove check boxes
    mCardsAdapter.notifyDataSetChanged();
    // update action bar
    supportInvalidateOptionsMenu();
    mActionBarSpinner.setVisibility(View.VISIBLE);
    mActionBarTitle.setVisibility(View.GONE);
  }
}

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

private void openMessageAtPosition(int position) {
  // Scroll message into view if necessary
  int listViewPosition = adapterToListViewPosition(position);
  if (listViewPosition != AdapterView.INVALID_POSITION &&
      (listViewPosition < listView.getFirstVisiblePosition() ||
      listViewPosition > listView.getLastVisiblePosition())) {
    listView.setSelection(listViewPosition);
  }
  MessageReference ref = getReferenceForPosition(position);
  // For some reason the listView.setSelection() above won't do anything when we call
  // onOpenMessage() (and consequently adapter.notifyDataSetChanged()) right away. So we
  // defer the call using MessageListHandler.
  handler.openMessage(ref);
}

代码示例来源: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);
}

相关文章

ListView类方法