Java Code Examples for android.widget.ListView.getLastVisiblePosition()

The following are Jave code examples for showing how to use getLastVisiblePosition() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lighthouse   File: PodcastsActivity.java   View Source Code Vote up 8 votes
private void updatePodcastRows() {
    ListView list = getListView();
    int first = list.getFirstVisiblePosition();
    int last = list.getLastVisiblePosition();
    for (int i = first; i <= last; i++) {
        View view = list.getChildAt(i - first);
        list.getAdapter().getView(i, view, list);
    }
}
 
Example 2
Project: GitHub   File: DownloadAdapter.java   View Source Code Vote up 6 votes
/**
 * 局部更新API
 */
public void notifyItemChanged(ListView listview, int position){
    int firstPos = listview.getFirstVisiblePosition();
    int lastPos = listview.getLastVisiblePosition();
    Job job = mData.get(position);
    if(position >= firstPos && position <= lastPos){
        View view = listview.getChildAt(position - firstPos); //NOTE
        DownloadAdapter.VH vh = (DownloadAdapter.VH) view.getTag();
        vh.progress.setProgress(job.progress);
        if(job.progress == 100){
            vh.btn.setText("完成");
        }
    }
}
 
Example 3
Project: qmui   File: QMUIViewHelper.java   View Source Code Vote up 6 votes
/**
 * 判断 ListView 是否已经滚动到底部
 *
 * @param listView 需要被判断的 ListView
 * @return
 */
public static boolean isListViewAlreadyAtBottom(ListView listView) {
    if (listView.getAdapter() == null || listView.getHeight() == 0) {
        return false;
    }

    if (listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1) {
        View lastItemView = listView.getChildAt(listView.getChildCount() - 1);
        if (lastItemView != null && lastItemView.getBottom() == listView.getHeight()) {
            return true;
        }
    }
    return false;
}
 
Example 4
Project: chromium-for-android-56-debug-video   File: AppMenu.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 5
Project: Android-DFU-App   File: UARTLogFragment.java   View Source Code Vote up 6 votes
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
	// Here we have to restore the old saved scroll position, or scroll to the bottom if before adding new events it was scrolled to the bottom.  
	final ListView list = getListView();
	final int position = mLogScrollPosition;
	final boolean scrolledToBottom = position == LOG_SCROLLED_TO_BOTTOM || (list.getCount() > 0 && list.getLastVisiblePosition() == list.getCount() - 1);

	mLogAdapter.swapCursor(data);

	if (position > LOG_SCROLL_NULL) {
		list.setSelectionFromTop(position, 0);
	} else {
		if (scrolledToBottom)
			list.setSelection(list.getCount() - 1);
	}
	mLogScrollPosition = LOG_SCROLL_NULL;
}
 
Example 6
Project: CXJPadProject   File: ChatUtils.java   View Source Code Vote up 6 votes
/**
 * 单个更新某个条目   只有可见的时候更新progress,
 * @param progress 当前进度
 * @param position 位置
 * @param lv_message Listview
    */
public static void updateProgressPartly(int progress,int position,ListView lv_message){
	int firstVisiblePosition = lv_message.getFirstVisiblePosition();
	int lastVisiblePosition = lv_message.getLastVisiblePosition();
	if(position>=firstVisiblePosition && position<=lastVisiblePosition){
		View view = lv_message.getChildAt(position - firstVisiblePosition);
		if(view.getTag() instanceof ImageMessageHolder){
			ImageMessageHolder vh = (ImageMessageHolder)view.getTag();
			vh.sobot_pic_progress_round.setProgress(progress);
		}
	}
}
 
Example 7
Project: QMUI_Android   File: QMUIViewHelper.java   View Source Code Vote up 6 votes
/**
 * 判断 ListView 是否已经滚动到底部。
 *
 * @param listView 需要被判断的 ListView。
 * @return ListView 已经滚动到底部则返回 true,否则返回 false。
 */
public static boolean isListViewAlreadyAtBottom(ListView listView) {
    if (listView.getAdapter() == null || listView.getHeight() == 0) {
        return false;
    }

    if (listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1) {
        View lastItemView = listView.getChildAt(listView.getChildCount() - 1);
        if (lastItemView != null && lastItemView.getBottom() == listView.getHeight()) {
            return true;
        }
    }
    return false;
}
 
Example 8
Project: decoy   File: ListViewUtil.java   View Source Code Vote up 6 votes
public static Object getViewHolderByIndex(ListView listView, int index) {
	int firstVisibleFeedPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount();
	int lastVisibleFeedPosition = listView.getLastVisiblePosition() - listView.getHeaderViewsCount();

	//只有获取可见区域的
	if (index >= firstVisibleFeedPosition && index <= lastVisibleFeedPosition) {
		View view = listView.getChildAt(index - firstVisibleFeedPosition);
		Object tag = view.getTag();
		return tag;
	} else {
		return null;
	}
}
 
Example 9
Project: sctalk   File: MessageActivity.java   View Source Code Vote up 6 votes
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();
        }
    }
}
 
Example 10
Project: orgzly-android   File: ListViewUtils.java   View Source Code Vote up 5 votes
public static boolean isIdVisible(ListView listView, long id) {
    final int firstVisible = listView.getFirstVisiblePosition();
    final int lastVisible = listView.getLastVisiblePosition();

    for (int pos = firstVisible; pos <= lastVisible; pos++) {
        long posId = listView.getItemIdAtPosition(pos);

        if (posId == id) {
            return true;
        }
    }

    return false;
}
 
Example 11
Project: Android-DFU-App   File: UARTLogFragment.java   View Source Code Vote up 5 votes
@Override
public void onSaveInstanceState(final Bundle outState) {
	super.onSaveInstanceState(outState);

	// Save the last log list view scroll position
	final ListView list = getListView();
	final boolean scrolledToBottom = list.getCount() > 0 && list.getLastVisiblePosition() == list.getCount() - 1;
	outState.putInt(SIS_LOG_SCROLL_POSITION, scrolledToBottom ? LOG_SCROLLED_TO_BOTTOM : list.getFirstVisiblePosition());
}
 
Example 12
Project: decoy   File: ListViewUtil.java   View Source Code Vote up 5 votes
public static boolean isLastMessageVisible(ListView messageListView) {
	if(messageListView == null || messageListView.getAdapter() == null) {
		return false;
	}
	
    if (messageListView.getLastVisiblePosition() >= messageListView.getAdapter().getCount() - 1 - messageListView.getFooterViewsCount()) {
        return true;
    } else {
        return false;
    }
}
 
Example 13
Project: lighthouse   File: PodcastsActivity.java   View Source Code Vote up 5 votes
private boolean isRowInIconLoadingRange(long id) {
    ListView list = getListView();
    int count = adapter.getCount();
    int first = list.getFirstVisiblePosition();
    int last = list.getLastVisiblePosition();
    int visible = last - first + 1;
    int start = Math.max(0, first - visible / 2);
    int end = Math.min(count - 1, last + visible / 2);
    for (int i = start; i <= end; i++) {
        if (id == adapter.getItemId(i)) {
            return true;
        }
    }
    return false;
}
 
Example 14
Project: lighthouse   File: PodcastsActivity.java   View Source Code Vote up 5 votes
private void updatePodcastRow(long id) {
    ListView list = getListView();
    int first = list.getFirstVisiblePosition();
    int last = list.getLastVisiblePosition();
    for (int i = first; i <= last; i++) {
        if (id == list.getItemIdAtPosition(i)) {
            View view = list.getChildAt(i - first);
            list.getAdapter().getView(i, view, list);
            break;
        }
    }
}
 
Example 15
Project: AOSP-Kayboard-7.1.2   File: WordListPreference.java   View Source Code Vote up 5 votes
void onWordListClicked(final View v) {
    // Note : v is the preference view
    final ViewParent parent = v.getParent();
    // Just in case something changed in the framework, test for the concrete class
    if (!(parent instanceof ListView)) return;
    final ListView listView = (ListView)parent;
    final int indexToOpen;
    // Close all first, we'll open back any item that needs to be open.
    final boolean wasOpen = mInterfaceState.isOpen(mWordlistId);
    mInterfaceState.closeAll();
    if (wasOpen) {
        // This button being shown. Take note that we don't want to open any button in the
        // loop below.
        indexToOpen = -1;
    } else {
        // This button was not being shown. Open it, and remember the index of this
        // child as the one to open in the following loop.
        mInterfaceState.setOpen(mWordlistId, mStatus);
        indexToOpen = listView.indexOfChild(v);
    }
    final int lastDisplayedIndex =
            listView.getLastVisiblePosition() - listView.getFirstVisiblePosition();
    // The "lastDisplayedIndex" is actually displayed, hence the <=
    for (int i = 0; i <= lastDisplayedIndex; ++i) {
        final ButtonSwitcher buttonSwitcher = (ButtonSwitcher)listView.getChildAt(i)
                .findViewById(R.id.wordlist_button_switcher);
        if (i == indexToOpen) {
            buttonSwitcher.setStatusAndUpdateVisuals(getButtonSwitcherStatus(mStatus));
        } else {
            buttonSwitcher.setStatusAndUpdateVisuals(ButtonSwitcher.STATUS_NO_BUTTON);
        }
    }
}