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


Java AbsListView.setSelection方法代碼示例

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


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

示例1: scrollToTop

import android.widget.AbsListView; //導入方法依賴的package包/類
public void scrollToTop() {
    if (child instanceof AbsListView) {
        AbsListView absListView = (AbsListView) child;
        absListView.setSelection(0);
    } else if (child instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) child;
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        layoutManager.scrollToPosition(0);
    }
}
 
開發者ID:LonelyMushroom,項目名稱:aarLibrary,代碼行數:11,代碼來源:XRefreshContentView.java

示例2: restoreBestPositionWithScroll

import android.widget.AbsListView; //導入方法依賴的package包/類
/**
  * Restore the best position possible in the list.
  *
  * @return the new last position
  */
 public static int restoreBestPositionWithScroll(final AbsListView listView, int selectedPosition,
         int firstVisiblePosition,  final int scroll) {
 	if(listView.getFirstVisiblePosition() <= selectedPosition && listView.getLastVisiblePosition()>=selectedPosition)
 		return selectedPosition;
     final int newPositionToSelect;
     newPositionToSelect = selectedPosition>=0?selectedPosition:0;
     if (newPositionToSelect < listView.getCount()) {
         //we select next enabled view
         for(int i = newPositionToSelect; i<listView.getCount(); i++){      
             if(i<listView.getAdapter().getCount()&&listView.getAdapter().isEnabled(i)){
                  //we don't want to loose scroll
                     final int pos = i;  
                     if(listView instanceof GridView){
                     	listView.setSelection(pos);
                         listView.smoothScrollToPositionFromTop(pos, scroll);
                     }
                     else if(listView instanceof ListView)
                         ((ListView)listView).setSelectionFromTop(pos, scroll);
                   
             
                 break;       
             }     
         }
         
         // Make sure the album list/grid has still the focus after changing the
         // view mode
         listView.postDelayed(new Runnable() {
	@Override
	public void run() {
		listView.requestFocus();		
	}
}, 200);
     }
     return newPositionToSelect;
 }
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:41,代碼來源:Utils.java


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