当前位置: 首页>>代码示例>>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;未经允许,请勿转载。