當前位置: 首頁>>代碼示例>>Java>>正文


Java ListView.getFirstVisiblePosition方法代碼示例

本文整理匯總了Java中android.widget.ListView.getFirstVisiblePosition方法的典型用法代碼示例。如果您正苦於以下問題:Java ListView.getFirstVisiblePosition方法的具體用法?Java ListView.getFirstVisiblePosition怎麽用?Java ListView.getFirstVisiblePosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.ListView的用法示例。


在下文中一共展示了ListView.getFirstVisiblePosition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updatePodcastRows

import android.widget.ListView; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:10,代碼來源:PodcastsActivity.java

示例2: scrollListBy

import android.widget.ListView; //導入方法依賴的package包/類
static void scrollListBy(ListView listView, int y) {
    int firstPosition = listView.getFirstVisiblePosition();
    if (firstPosition != -1) {
        View firstView = listView.getChildAt(0);
        if (firstView != null) {
            listView.setSelectionFromTop(firstPosition, firstView.getTop() - y);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:10,代碼來源:ListViewCompatDonut.java

示例3: onKeyDown

import android.widget.ListView; //導入方法依賴的package包/類
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Shortcuts that work no matter what is selected
    if (QMail.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);
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:27,代碼來源:K9ListActivity.java

示例4: notifyItemChanged

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * 局部更新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("完成");
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:DownloadAdapter.java

示例5: getViewByPosition

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * @see <a href="http://stackoverflow.com/questions/24811536/android-listview-get-item-view-by-position" >android - listview get item view by position
</a>
 * @param pos
 * @param listView
 * @return
 */
public static 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);
    }
}
 
開發者ID:ProjectFishpond,項目名稱:TPondof,代碼行數:19,代碼來源:Utils.java

示例6: menuItemContentChanged

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:38,代碼來源:AppMenu.java

示例7: canTargetScrollVertically

import android.widget.ListView; //導入方法依賴的package包/類
public boolean canTargetScrollVertically(int direction) {
    ListView target = this.mTarget;
    int itemCount = target.getCount();
    if (itemCount == 0) {
        return false;
    }
    int childCount = target.getChildCount();
    int firstPosition = target.getFirstVisiblePosition();
    int lastPosition = firstPosition + childCount;
    if (direction > 0) {
        if (lastPosition >= itemCount && target.getChildAt(childCount - 1).getBottom() <= target.getHeight()) {
            return false;
        }
    } else if (direction >= 0) {
        return false;
    } else {
        if (firstPosition <= 0 && target.getChildAt(0).getTop() >= 0) {
            return false;
        }
    }
    return true;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:23,代碼來源:ListViewAutoScrollHelper.java

示例8: updateProgressPartly

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * 單個更新某個條目   隻有可見的時候更新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);
		}
	}
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:18,代碼來源:ChatUtils.java

示例9: getViewByPosition

import android.widget.ListView; //導入方法依賴的package包/類
private 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);
    }
}
 
開發者ID:Bartout-Team,項目名稱:Bartout,代碼行數:12,代碼來源:DrinkBeverageActivity.java

示例10: canListViewScrollUp

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * Utility method to check whether a {@link ListView} can scroll up from it's current position.
 * Handles platform version differences, providing backwards compatible functionality where
 * needed.
 */
private static boolean canListViewScrollUp(ListView listView) {
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        // For ICS and above we can call canScrollVertically() to determine this
        return ViewCompat.canScrollVertically(listView, -1);
    } else {
        // Pre-ICS we need to manually check the first visible item and the child view's top
        // value
        return listView.getChildCount() > 0 &&
                (listView.getFirstVisiblePosition() > 0
                        || listView.getChildAt(0).getTop() < listView.getPaddingTop());
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:SwipeRefreshListFragment.java

示例11: onLoadingFinish

import android.widget.ListView; //導入方法依賴的package包/類
@Override
    public AnimatorUpdateListener onLoadingFinish(final RefreshKernel kernel, final int footerHeight, int startDelay, final int duration) {
        if (mScrollableView != null && kernel.getRefreshLayout().isEnableScrollContentWhenLoaded()) {
            if (!canScrollDown(mScrollableView)) {
                return null;
            }
            if (mScrollableView instanceof AbsListView && !(mScrollableView instanceof ListView) && Build.VERSION.SDK_INT < 19) {
                if (startDelay > 0) {
                    kernel.getRefreshLayout().getLayout().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
                        }
                    }, startDelay);
                } else {
                    ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
                }
                return null;
            }
            return new AnimatorUpdateListener() {
                int lastValue = kernel.getSpinner();
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int value = (int) animation.getAnimatedValue();
                    try {
                        if (mScrollableView instanceof ListView) {
                            if (Build.VERSION.SDK_INT >= 19) {
                                ((ListView) RefreshContentWrapper.this.mScrollableView).scrollListBy(value - lastValue);
                            } else {
//                                ListViewCompat.scrollListBy((ListView) mScrollableView, value - lastValue);
                                ListView listView = (ListView) RefreshContentWrapper.this.mScrollableView;
                                final int firstPosition = listView.getFirstVisiblePosition();
                                if (firstPosition == ListView.INVALID_POSITION) {
                                    return;
                                }
                                final View firstView = listView.getChildAt(0);
                                if (firstView == null) {
                                    return;
                                }
                                final int newTop = firstView.getTop() - (value - lastValue);
                                listView.setSelectionFromTop(firstPosition, newTop);
                            }
                        } else {
                            mScrollableView.scrollBy(0, value - lastValue);
                        }
                    } catch (Throwable ignored) {
                        //根據用戶反饋,此處可能會有BUG
                    }
                    lastValue = value;
                }
            };
        }
        return null;
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:55,代碼來源:RefreshContentWrapper.java

示例12: scrollToTop

import android.widget.ListView; //導入方法依賴的package包/類
/**
 * listview滾動到頂部
 *
 * @param animate 是否動畫
 * @return
 */
public UDBaseListOrRecyclerView scrollToTop(final int offset, final boolean animate) {
    final ListView lv = getListView();
    if (lv != null) {
        if (animate) {
            if (lv.getFirstVisiblePosition() > 7) {//hack fast scroll
                lv.setSelection(7);
            }
            lv.smoothScrollToPositionFromTop(0, offset);
        } else {
            lv.setSelectionFromTop(0, offset);
        }
    }
    return this;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:21,代碼來源:UDBaseListView.java

示例13: isIdVisible

import android.widget.ListView; //導入方法依賴的package包/類
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;
}
 
開發者ID:orgzly,項目名稱:orgzly-android,代碼行數:15,代碼來源:ListViewUtils.java

示例14: getScroll

import android.widget.ListView; //導入方法依賴的package包/類
private int getScroll() {
	ListView listview = basePagedItemAdapter.getListView();
	View c = listview.getChildAt(0); //this is the first visible row
	int scrollY = -c.getTop();
	listViewItemHeights.put(listview.getFirstVisiblePosition(), c.getHeight());
	for (int i = 0; i < listview.getFirstVisiblePosition(); i ++) {
		if (listViewItemHeights.get(i) != null) { // (this is a sanity check)
			scrollY += listViewItemHeights.get(i); //add all heights of the views that are gone
		}
	}
	return scrollY;
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:13,代碼來源:BBSPullToRequestView.java

示例15: saveListPosition

import android.widget.ListView; //導入方法依賴的package包/類
public void saveListPosition() {
    if (mAdapter != null) {
        ListView l = getListView();
        int position = l.getFirstVisiblePosition();
        View v = l.getChildAt(0);
        int top = (v == null) ? 0 : v.getTop();
        setListPosition(new Position(position, top));
    }
}
 
開發者ID:brevent,項目名稱:prevent,代碼行數:10,代碼來源:PreventFragment.java


注:本文中的android.widget.ListView.getFirstVisiblePosition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。