@Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (mContentView.getLastVisiblePosition() >= totalCount - 1 && !isLoading) { footerContent.setVisibility(View.VISIBLE); searchNextPage(); } }
/** 判断是否到了最底部 */ private boolean isBottom() { if (mListView != null && mListView.getAdapter() != null) { return mListView.getLastVisiblePosition() == (mListView.getAdapter().getCount() - 1); } return false; }
/** * Notifies the menu that the contents of the menu item specified by {@code menuRowId} have * changed. This should be called if icons, titles, etc. are changing for a particular menu item * while the menu is open. * * @param menuRowId The id of the menu item to change. This must be a row id and not a child id. */ public void menuItemContentChanged(int menuRowId) { // Make sure we have all the valid state objects we need. if (mAdapter == null || mMenu == null || mPopup == null || mPopup.getListView() == null) { return; } // Calculate the item index. int index = -1; int menuSize = mMenu.size(); for (int i = 0; i < menuSize; i++) { if (mMenu.getItem(i).getItemId() == menuRowId) { index = i; break; } } if (index == -1) return; // Check if the item is visible. ListView list = mPopup.getListView(); int startIndex = list.getFirstVisiblePosition(); int endIndex = list.getLastVisiblePosition(); if (index < startIndex || index > endIndex) return; // Grab the correct View. View view = list.getChildAt(index - startIndex); if (view == null) return; // Cause the Adapter to re-populate the View. list.getAdapter().getView(index, view, list); }
private void reset() { int begin = mListView.getFirstVisiblePosition(); int end = mListView.getLastVisiblePosition(); if (mAdapter.cancelSelection(mListView, begin, end) < 1 && mFromMenu) { mActionMode.finish(); } }
public View getView(int position, View convertView, ViewGroup parent) { AlbumDescriptor albumDescriptor = mData.get(position); if (null == convertView || !albumDescriptor.getAlbumId().equals(convertView.getTag())) { LayoutInflater inflater = LayoutInflater.from(mContext); convertView = (ViewGroup) inflater.inflate(R.layout.album_list_item, parent, false); convertView.setTag(albumDescriptor.getAlbumId()); } ListView theListView = null; if (parent instanceof ListView) { theListView = (ListView) parent; } final TextView albumText = (TextView) convertView.findViewById(R.id.item_title); albumText.setText("" + albumDescriptor.getPhotosCount() + " hot photos"); final ImageViewProxy imgView = (ImageViewProxy) convertView.findViewById(R.id.album_cover); imgView.setImageLink(albumDescriptor.getCoverLinkage()); imgView.setLoadingIcon(Constants.IMG_LOADING); imgView.setImageChangeListener( new ImageViewProxy.OnImageChangeListiner() { @Override public void onImageChanged() { Rect rect = imgView.getDrawable().copyBounds(); Point size = GraphicsUtil.getDisplaySize(imgView.getContext()); if (0 == rect.width() || 0 == size.x) { // wrong, possible 'divided by 0' return; } // TODO HERE TO CALC // suppose the image is wider than screen width int height = rect.height() * imgView.getLayoutParams().width / rect.width(); // size.x is screen width. /* if(size.x > rect.width()) { //TODO HERE TO CALC height = (int)(rect.height() * 1.1); } imgView.setScaleType(ImageView.ScaleType.FIT_CENTER); imgView.getLayoutParams().height = height; imgView.requestLayout(); */ } }); if (position > theListView.getFirstVisiblePosition() - PRE_LOAD_COUNT || position < theListView.getLastVisiblePosition() + PRE_LOAD_COUNT) { imgView.show(); } albumDescriptor.printInfo(); return convertView; }
private void setAllUnselected() { for (int i = 0; i <= (mListView.getLastVisiblePosition() - mListView.getFirstVisiblePosition()); i++) mListView .getChildAt(i) .setBackgroundColor(getActivity().getResources().getColor(R.color.non_selected_color)); }
private void reprioritizeDownloads() { int lastVisibleItem = listView.getLastVisiblePosition(); if (lastVisibleItem >= 0) { int firstVisibleItem = listView.getFirstVisiblePosition(); adapter.prioritizeViewRange( firstVisibleItem, lastVisibleItem, PROFILE_PICTURE_PREFETCH_BUFFER); } }
/** * Highlight current playing item Make the playing item can be seen. * * @param position */ private void onItemPlay(int position) { // Make the the playing item can be seen. mMusicListView.smoothScrollToPosition(position); int prePlayingPosition = mMusicListAdapter.getPlayingPosition(); if (prePlayingPosition >= mMusicListView.getFirstVisiblePosition() && prePlayingPosition <= mMusicListView.getLastVisiblePosition()) { int preItem = prePlayingPosition - mMusicListView.getFirstVisiblePosition(); ((ViewGroup) mMusicListView.getChildAt(preItem)).getChildAt(0).setVisibility(View.INVISIBLE); } mMusicListAdapter.setPlayingPosition(position); if (mMusicListView.getLastVisiblePosition() < position || mMusicListView.getFirstVisiblePosition() > position) return; int currentItem = position - mMusicListView.getFirstVisiblePosition(); ((ViewGroup) mMusicListView.getChildAt(currentItem)).getChildAt(0).setVisibility(View.VISIBLE); }
public static void ensureVisible(ListView list, int positionToShow) { // TODO could be enhanced by using setSelectionFromTop(). setSelection // always scrolls the list to the same offset, would prefer to show item // at top/bottom depending on direction if (positionToShow < list.getFirstVisiblePosition() || positionToShow > list.getLastVisiblePosition()) { list.setSelection(positionToShow); } }
public void loadImage() { int start = mListView.getFirstVisiblePosition(); int end = mListView.getLastVisiblePosition(); if (end >= getCount()) { end = getCount() - 1; } syncImageLoader.setLoadLimit(start, end); syncImageLoader.unlock(); }
private boolean isBottom() { if (mListView.getCount() > 0) { if (mListView.getLastVisiblePosition() == mListView.getAdapter().getCount() - 1 && mListView.getChildAt(mListView.getChildCount() - 1).getBottom() <= mListView.getHeight()) { return true; } } return false; }
private void updateSubTabUI(boolean refresh) { int lastPosition = contentList.getLastVisiblePosition(); Log.d(TAG, "lastVisible position is " + lastPosition); FacebookEventAdapter fea = new FacebookEventAdapter(FacebookEventActivity.this, event, withFooterView, simpleViewMode); contentList.setAdapter(fea); // if after refreshing, do not set select position. if (refresh == false) { contentList.setSelection(lastPosition + 1); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Refresh the app that was just edited, if it's visible in the list ListView list = (ListView) findViewById(R.id.lstApps); if (requestCode >= list.getFirstVisiblePosition() && requestCode <= list.getLastVisiblePosition()) { View v = list.getChildAt(requestCode - list.getFirstVisiblePosition()); list.getAdapter().getView(requestCode, v, list); } }
@Override public boolean getIsListViewToBottom() { if ((singleChatLv.getChildAt(-1 + singleChatLv.getChildCount()).getBottom() > singleChatLv.getHeight()) || (singleChatLv.getLastVisiblePosition() != -1 + singleChatLv.getAdapter().getCount())) { return false; } else { return true; } }
private void updateView(int index) { int firstVisiblePosition = lv_no_receive.getFirstVisiblePosition(); int lastVisiblePosition = lv_no_receive.getLastVisiblePosition(); if (index >= firstVisiblePosition && index <= lastVisiblePosition) { View view = lv_no_receive.getChildAt(index - firstVisiblePosition); if (view.getTag() instanceof NoReceivedAdapter.ExpressHolder) { NoReceivedAdapter.ExpressHolder vh = (NoReceivedAdapter.ExpressHolder) view.getTag(); vh.tv_express_notice.setBackgroundDrawable(CommonUtils.creatRectangleDrawble("#d0d0d0")); // 改变状态 不能再通知 noReceivedAdapter.getItem(index).canNotify = false; } } }
/** * Scroll view to the center of the list * * @param view * @param parent */ public static void scrollViewToCenter(View view, ListView parent) { ListAdapter items = parent.getAdapter(); int viewY = view.getTop() + view.getHeight() / 2 - parent.getHeight() / 2; if (viewY < 0 && parent.getFirstVisiblePosition() == 0) { parent.smoothScrollToPosition(0); } else if (viewY > 0 && parent.getLastVisiblePosition() == items.getCount() - 1) { parent.smoothScrollToPosition(items.getCount() - 1); } else { Command.invoke(SCROLL_LIST_FOR_DISTANCE_IN_ANY_MILLIS) .args(parent, viewY, 300) .only() .sendDelayed(100); } }
// 肯定是在当前的session内 private void onMsgRecv(MessageEntity entity) { logger.d("message_activity#onMsgRecv"); imService.getUnReadMsgManager().ackReadMsg(entity); logger.d("chat#start pushList"); pushList(entity); ListView lv = lvPTR.getRefreshableView(); if (lv != null) { if (lv.getLastVisiblePosition() < adapter.getCount()) { textView_new_msg_tip.setVisibility(View.VISIBLE); } else { scrollToBottomListItem(); } } }
private void changeListView() { int visiblePosition = leftView.getFirstVisiblePosition(); int lastVisiblePosition = leftView.getLastVisiblePosition(); int selectedItemNum = selectItemPosition - visiblePosition; // Log.d("LogonActivity", String.format("SildingLayout:visiblePosition:%d ,lastVisiblePosition // %d",visiblePosition,lastVisiblePosition)); for (int i = 0; i <= lastVisiblePosition - visiblePosition; i++) // 获取ListView的所有Item数目 { // LinearLayout linearlayout = (LinearLayout)mListView.getChildAt(i); View view = leftView.getChildAt(i); if (view != null && view.getTag() != null) { LeftViewAdapter.ViewHolder holder = (LeftViewAdapter.ViewHolder) view.getTag(); // holder.textView.setText(String.valueOf(parentViewScrollX)); holder.description.setAlpha(Math.abs(parentView.getX()) / viewWidth); if (i == selectedItemNum) { holder.textView.setText("我被选中了!"); } } } }
private void updateRead() { Log.d(TAG, "Updating buffer read, chat is visible: " + getUserVisibleHint()); if (adapter.buffer != null) { // Don't save position if list is at bottom if (backlogList.getLastVisiblePosition() == adapter.getCount() - 1) { adapter.buffer.setTopMessageShown(0); } else { adapter.buffer.setTopMessageShown(adapter.getListTopMessageId()); } if (adapter.buffer.getUnfilteredSize() != 0) { BusProvider.getInstance() .post(new ManageChannelEvent(adapter.getBufferId(), ChannelAction.MARK_AS_READ)); BusProvider.getInstance() .post( new ManageMessageEvent( adapter.getBufferId(), adapter.buffer.getUnfilteredBacklogEntry(adapter.buffer.getUnfilteredSize() - 1) .messageId, MessageAction.LAST_SEEN)); } } }
private boolean isCurrentListViewItemVisible(int position) { int first = listView.getFirstVisiblePosition(); int last = listView.getLastVisiblePosition(); return first <= position && position <= last; }
public void testTouchEvents() { TouchUtils.scrollToBottom(this, getActivity(), list); getInstrumentation().waitForIdleSync(); assertEquals(list.getLastVisiblePosition(), 24); }
package com.chang.news.util;
@Override public int[] findLastVisibleItemPositions() { return new int[] {mListView.getLastVisiblePosition()}; }