Code example for AbsListView

Methods: getContext, setOnItemClickListener, setOnItemLongClickListener, setOnScrollListener

0
	 * @param absListView 列表视图 
	 */ 
	public void setAbsListView(AbsListView absListView) {
		if(absListView != null){
			this.absListView = absListView;
			absListView.setOnScrollListener(new OnScrollListener() {
				@Override 
				public void onScrollStateChanged(AbsListView view, int scrollState) {
					//如果已经开启了滚动不刷新数据模式 
					if(isOpenedOnScrollNoRefreshDataMode()){ 
						//如果是飞速滚动就标记为不刷新数据,否则就标记为刷新数据并刷新 
						if(scrollState == OnScrollListener.SCROLL_STATE_FLING){
							setRefershData(false); 
						}else{ 
							setRefershData(true); 
							notifyDataSetChanged();
						} 
					} 
					if(getOnScrollListener() != null){ 
						getOnScrollListener().onScrollStateChanged(view, scrollState);
					} 
				} 
				 
				@Override 
				public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
					if(getOnScrollListener() != null){ 
						getOnScrollListener().onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
					} 
				} 
			}); 
			 
			absListView.setOnItemLongClickListener(new OnItemLongClickListener() {
				@Override 
				public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
					boolean result = true;
					//如果已经开启了分页模式 
					if(isOpenedChoiceMode()){ 
						//如果已经进入了分页模式就退出,反之就进入 
						if(isIntoChoiceMode()){ 
							exitChoiceMode(); 
						}else{ 
							intoChoiceMode(); 
							choiceClickHandle((int) id, true);
						} 
					}else if(getOnItemLongClickListener() != null){ 
						result = getOnItemLongClickListener().onItemLongClick(parent, view, getRealPosition((int) id), id);
					} 
					return result ;
				} 
			}); 
			 
			absListView.setOnItemClickListener(new OnItemClickListener() {
				@Override 
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
					//如果已经开启并进入了分页模式 
					if(isOpenedChoiceMode() && isIntoChoiceMode()){ 
						choiceClickHandle((int) arg3, true);
					}else if(getOnItemClickListener() != null){ 
						getOnItemClickListener().onItemClick(arg0, arg1, getRealPosition((int) arg3), arg3);
					} 
				} 
			}); 
			 
			setContext(absListView.getContext());
		} 
	} 
	 
	/** 
	 * 获取选择模式监听器